StructError
Error returned by a failed struct parse, aggregating one or more StructIssues and their formatters.
@defjs/core · Type
Signature
class StructError extends Error { readonly issues: StructIssue[]; constructor(issues: StructIssue[]); format(): FormattedStructError; flatten(): FlattenedStructError; prettify(): string; }
name is 'StructError'. Construct it with constructor(issues: StructIssue[]). issues is the readonly list of those issues. message is the issue's message for a single issue, N struct issues: <first message> for several, and Struct parse failed for none.
Default issue messages name the received kind and omit the value, so message and prettify() can be logged. For example, Expected number at id, received string. message and the formatters use that text. The raw value stays on StructIssue.received; custom errorMap text is used verbatim and can reintroduce sensitive values.
Use format(), flatten(), or prettify() to present issues to callers.
-
struct.parsestops at the first failure, soissuesholds one StructIssue there. -
format()returns a FormattedStructError tree. Each node has an_errorsarray, and nested keys followissue.path. -
flatten()returns a FlattenedStructError: messages with an empty path go toformErrors, the others are grouped by the first path segment infieldErrors. -
prettify()returns one× path: messageline per issue. An empty path is shown as<root>.
Members
Prop
Type
issues StructIssue[]Issues collected for this failure, in encounter order.
format () => FormattedStructErrorBuild a nested error tree keyed by path segments.
flatten () => FlattenedStructErrorSplit issues into root formErrors and first-segment fieldErrors.
prettify () => stringRender a multi-line, human-readable summary of all issues.
Each line uses the issue message, which names the received kind and omits the value.