Defjs
Core

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.parse stops at the first failure, so issues holds one StructIssue there.

  • format() returns a FormattedStructError tree. Each node has an _errors array, and nested keys follow issue.path.

  • flatten() returns a FlattenedStructError: messages with an empty path go to formErrors, the others are grouped by the first path segment in fieldErrors.

  • prettify() returns one × path: message line per issue. An empty path is shown as <root>.

Members

Prop

Type

issues StructIssue[]

Issues collected for this failure, in encounter order.

format () => FormattedStructError

Build a nested error tree keyed by path segments.

flatten () => FlattenedStructError

Split issues into root formErrors and first-segment fieldErrors.

prettify () => string

Render a multi-line, human-readable summary of all issues.

Each line uses the issue message, which names the received kind and omits the value.

Edit this page on GitHub
Released under the MIT License. · Copyright © 2026 MunMunMiao