Class Problem
- Direct Known Subclasses:
Unchecked
Class used for describing errors and other issues with user defined input. Problems are hierarchical, which
is used to 'target' where issues are found, e.g. a problem with your function that is in your model that is in your
project might have three levels, e.g. There was a problem in your project... -> There was a problem with your
model... -> The function 'hazard-calculator' does not exist
This code is going through a 'transition' phase as it moves away from free form messages to something more structured and linked to the i18n system. Over time, we should: * purge all the code related to default messages * use annotations to apply structure to the various args, e.g. an 'expected' and 'actual' argument
See Problems
for tips on constructing Problems.
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDeprecated.use the ProblemCode-based constructor insteadProblem
(List<Problem> children, ProblemCode code, Object... args) Problem
(Problem.Severity severity, String message) Deprecated.use the ProblemCode-based constructor insteadProblem
(Problem.Severity severity, String message, Object[] args, Throwable t) Deprecated.use the ProblemCode-based constructor insteadProblem
(Problem.Severity severity, String defaultMessageFormat, Object[] arguments, Throwable exception, ProblemCode code, nz.org.riskscape.problem.Problem.AffectedMetadata affected, List<Problem> children) Problem
(Problem.Severity severity, ProblemCode code, Object... args) Same aserror(ProblemCode, Object...)
, but where you need to use a different severity, e.g. -
Method Summary
Modifier and TypeMethodDescriptionCopy this Problem but add details of the specific thing that the problem affects.boolean
protected boolean
static Problem
Deprecated.use the ProblemCode-based constructor insteadstatic Problem
Deprecated.use the ProblemCode-based constructor insteadstatic String
debugString
(List<Problem> problems) Variation ofdebugString(Problem)
that dumps out a list of problemsstatic String
debugString
(Problem origin) boolean
static Problem
Deprecated.use the ProblemCode-based constructor insteadstatic Problem
Deprecated.use the ProblemCode-based constructor insteadstatic Problem
error
(ProblemCode code, Object... args) Create an problem withProblem.Severity.ERROR
with a particularProblemCode
and message arguments.static Problem
Deprecated.use the ProblemCode-based constructor insteadfilterAffected
(Collection<? extends Problem> problems, Class<?> contextClass) Filters the list of Problems (and their children) based on the affected class, e.g.Finds any exception info related to this problem, including exceptions that may have been caught by child/nested Problems<T> Optional<T>
getAffected
(Class<T> classOfThing) With Problems, there is usually something this is most affected by the Problem, e.g.Class<?>
Object[]
getCode()
boolean
static boolean
hasErrors
(Collection<? extends Problem> problems) int
hashCode()
static Problem
Deprecated.use the ProblemCode-based constructor insteadboolean
isError()
boolean
isFatal()
static Problem.Severity
max
(Collection<? extends Problem> children) setChildren
(List<Problem> newChildren) Copy this Problem but replace the children.static <T extends Throwable>
voidtoString()
static Problem
Deprecated.use the ProblemCode-based constructor insteadstatic Problem
Deprecated.use the ProblemCode-based constructor insteadwithChildren
(List<? extends Problem> moreChildren) Copy this Problem but add in more children.withChildren
(Problem... moreChildren) Copy this Problem but with a new exceptionCopy this Problem but with a new severity
-
Field Details
-
severity
-
-
Constructor Details
-
Problem
Deprecated.use the ProblemCode-based constructor instead -
Problem
Deprecated.use the ProblemCode-based constructor instead -
Problem
@Deprecated public Problem(List<Problem> children, Problem.Severity severity, String message, Object[] args) Deprecated.use the ProblemCode-based constructor instead -
Problem
Same as
error(ProblemCode, Object...)
, but where you need to use a different severity, e.g. INFO, WARNING, etc. -
Problem
-
Problem
public Problem(Problem.Severity severity, String defaultMessageFormat, Object[] arguments, Throwable exception, ProblemCode code, nz.org.riskscape.problem.Problem.AffectedMetadata affected, List<Problem> children)
-
-
Method Details
-
info
Deprecated.use the ProblemCode-based constructor instead -
warning
Deprecated.use the ProblemCode-based constructor instead -
warning
Deprecated.use the ProblemCode-based constructor instead -
error
Deprecated.use the ProblemCode-based constructor instead -
error
Deprecated.use the ProblemCode-based constructor instead -
fatal
Deprecated.use the ProblemCode-based constructor instead -
composite
Deprecated.use the ProblemCode-based constructor insteadBuilds a
Problem
that contains the childProblem
s.The level of the the returned
Problem
is the most severe from those of the children.- Parameters:
children
- the problems the new Problem should wrap
-
composite
@Deprecated public static Problem composite(Problem.Severity severity, List<Problem> children, String message, Object... args) Deprecated.use the ProblemCode-based constructor insteadBuilds a
Problem
that contains the childProblem
s, forcing a particular severity for the created parent.- Parameters:
children
- the problems the new Problem should wrap
-
error
Create an problem with
Problem.Severity.ERROR
with a particularProblemCode
and message arguments. -
max
-
hasErrors
-
throwIfErrors
public static <T extends Throwable> void throwIfErrors(List<Problem> problems, Function<List<Problem>, T> supplier) throws T- Throws:
T extends Throwable
-
withChildren
-
withChildren
Copy this Problem but add in more children.
-
setChildren
Copy this Problem but replace the children.
-
withSeverity
Copy this Problem but with a new severity
-
withException
Copy this Problem but with a new exception
-
affecting
Copy this Problem but add details of the specific thing that the problem affects. E.g. the specific Parameter or pipeline Step affected, etc. Note that there are several variants as in some cases we may know the class and name but not have an object, whereas other cases may have an object but no name.
-
affecting
-
isError
public boolean isError() -
isFatal
public boolean isFatal() -
hasChildren
public boolean hasChildren() -
getMessage
-
getDefaultMessage
-
getAffectedName
- Returns:
- the name of the thing affected by this Problem (or an empty String if there is no such context associated with it)
-
getAffectedObject
- Returns:
- the thing affected by this Problem, e.g. the Parameter object. Returns Optional.empty() if there is no specific object affected.
-
getAffectedClass
- Returns:
- the class of thing affected by this Problem, e.g. Parameter.class. Returns Object.class if this is unknown.
-
affects
- Returns:
- true if the Problem affects the given class or superclass
-
getAffected
With Problems, there is usually something this is most affected by the Problem, e.g. a Parameter or a File or a Bookmark. This checks if this Problem affects the class given, and if so, returns that thing. E.g. 'I know this Problem affects a File, gimme the File'.
-
filterAffected
public static List<Problem> filterAffected(Collection<? extends Problem> problems, Class<?> contextClass) Filters the list of Problems (and their children) based on the affected class, e.g. find any/all problems that affect a Parameter, Step, etc. A flattened list is returned, i.e. it may be a mix of parents and children, regardless of where they occur in the problem hierarchy.
- Returns:
- a list of Problems that affect the given class. Or an empty list, if no Problems affect the given class.
-
debugString
- Returns:
- a string that gives some idea of the structure of this problem and its children, but without requiring any i18n resources to give actual user-facing error messages
-
debugString
Variation of
debugString(Problem)
that dumps out a list of problems -
getChildren
-
toString
-
findAnyException
Finds any exception info related to this problem, including exceptions that may have been caught by child/nested Problems
-
equals
-
canEqual
-
hashCode
public int hashCode() -
getSeverity
-
getArguments
-
getException
-
getCode
-