Class Problems
Helper 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)
.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Problem
static Problem
errorWith
(ProblemCode code, Object thing, Object... otherArgs) Creates a Problem for an error found with a given object.static Problem
static Problem
static Problem
Collates the children into a top-level problem: "Problems found with {thing}"static Problem
Creates a simple "Problems found with {thing}" problem with optional child problems.static <T extends ProblemFactory>
TGets a (proxied) ProblemFactory that can be used to generate Problems.static Problem
parseError
(Object expected) Produces an error: "Failed to parse [expectedThing]' E.g.static Problem
toSingleProblem
(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).
-
Constructor Details
-
Problems
public Problems()
-
-
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
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);
-