Interface Problems
The Problems interface exists to abstract over a single Problem or a collection of them (ProblemList),
because most of the time when dealing with errors it doesn't matter whether you have one or many, you just want to
pass one or more around.
Helpers for generating Problem objects.
General tips:
- Try to reuse existing ProblemFactory APIs where possible.
- To help make messages reusable, try to think in generic terms - use '[thing]' as a
placeholder in your message. E.g. use "[thing] was invalid" over the more specific
"pipeline step '[name]' was invalid".
- Use objects as building blocks in your message, i.e. just pass in the whole NamedStep
as an arg rather than using NamedStep.getName(). This means we can display things in
a consistent, user-friendly, translatable way. Displaying these objects args is handled
in ObjectRenderer.
- If you don't have an instance of a particular object, you may be able to use
ProblemPlaceholder as a placeholder.
- If it's an exception, always use caught(Throwable).
Never use Throwable.getMessage() directly.
- If you just want to group or nest problems together,
use foundWith(Object, List).
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic Problemstatic ProblemerrorWith(ProblemCode code, Object thing, Object... otherArgs) Creates a Problem for an error found with a given object.static Problemstatic Problemstatic ProblemCollates the children into a top-level problem: "Problems found with {thing}"static ProblemCreates a simple "Problems found with {thing}" problem with optional child problems.static Problemstatic Problemsstatic Problemsstatic <T extends ProblemFactory>
TGets a (proxied) ProblemFactory that can be used to generate Problems.booleanisEmpty()default booleanstatic ProblemparseError(Object expected) Produces an error: "Failed to parse [expectedThing]' E.g.stream()toList()Convert this Problems in to a (possibly empty) list of ProblemsConvert this Problems in to a single problem, or empty if this is Problems.NONEstatic ProblemtoSingleProblem(List<Problem> children) Helper for wrapping a list of problems with a single problem - useful where you go from a multiple problem API to a single problem API (sigh).Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Field Details
-
NONE
An empty ProblemList
-
-
Method Details
-
errorWith
Creates a Problem for an error found with a given object. I.e. there is clearly a thing (Parameter, Step, Bookmark, etc) that is associated with or affected by this Problem. This results in the same end message as
Problem.error(ProblemCode, Object...), but stores some extra contextual info with the Problem. Note that the 'thing' should always be the first MessageFormat argument, i.e. {0} in the .properties file. The affected thing's contextual info (i.e. class, name) is preserved and can be interrogated later (i.e. byProblem.getAffectedClass()). -
foundWith
-
foundWith
Collates the children into a top-level problem: "Problems found with {thing}"
-
foundWith
Creates a simple "Problems found with {thing}" problem with optional child problems. This can be a useful placeholder when you want to nest problems but you don't have all the child problems yet. Or you only have a single child problem rather than a list.
-
foundWith
-
foundWith
-
toSingleProblem
Helper for wrapping a list of problems with a single problem - useful where you go from a multiple problem API to a single problem API (sigh).
Returns the 0th element if children is of size 1
-
caught
-
parseError
Produces an error: "Failed to parse [expectedThing]' E.g. Failed to parse pipeline 'foo' Similar to
ExpressionProblems.cannotParse(Object, String)but useful when parsing something other than an expressions, or when we don't have easy access to the problematic expression itself. -
get
Gets a (proxied) ProblemFactory that can be used to generate Problems. The standard usage would be: Problem problem = Problem.create(MyFactory.class).myErrorApi(args);
-
from
- Returns:
- the correct thing from a list of children, either NONE, the individual problem, or a
ProblemList
-
from
-
toProblem
Convert this Problems in to a single problem, or empty if this is Problems.NONE
-
toList
Convert this Problems in to a (possibly empty) list of Problems
- Returns:
-
stream
- Returns:
- a stream over any individual
Problems
-
isPresent
default boolean isPresent() -
isEmpty
boolean isEmpty()- Returns:
- true if this Problems is NONE
-
getSeverity
Problem.Severity getSeverity()- Returns:
- the maximum severity of any
Problems, or INFO if empty.
-