can1357/oh-my-pi · error · TraversalError
TraversalError thrown by OmpErrors.throw() with message equa
Error message
TraversalError thrown by OmpErrors.throw() with message equal to errors summary
What it means
`Type.assert` validation failures are aggregated into an `OmpErrors` object; calling `.throw()` wraps it in a `TraversalError`. The error's message equals the human-readable summary of all traversal errors found during validation. Catching it gives you the full `errors` object for structured inspection of every failed check.
Source
Thrown at packages/omptype/src/errors.ts:424
entry =>
Object.is(entry.data, entries[0].data) &&
entry.path.length === entries[0].path.length &&
entry.path.every((key, index) => key === entries[0].path[index]),
)
) {
const at = formatPath(entries[0].path);
const actual = typeof entries[0].data === "string" ? JSON.stringify(entries[0].data) : String(entries[0].data);
return `${at}${at === "" ? "" : " "}(${actual}) must be...\n${entries.map(entry => ` ◦ ${entry.expected}`).join("\n")}`;
}
return entries.map(error => error.message).join(this.#separator);
}
toString(): string {
return this.summary;
}
throw(): never {
throw new TraversalError(this);
}
}
/** Error thrown by `Type.assert` on invalid input. */
export class TraversalError extends Error {
constructor(readonly errors: OmpErrors) {
super(errors.summary);
this.name = "TraversalError";
}
}
/**
* Definition/usage error thrown while building a schema — malformed string
* DSL, unsupported composition, or an illegal builder call. Distinct from
* validation failures, which are returned as {@link OmpErrors}.
*/
export class OmpTypeError extends Error {
constructor(message: string) {View on GitHub (pinned to 9690622007)
Solutions
- Fix the data so it satisfies the type; read `error.summary` for the exact failing paths.
- Catch `TraversalError` and inspect `err.errors` for per-path diagnostics.
- Use `type.allows(value)` or a `try` around `assert` when input validity is uncertain.
Example fix
// before
type.assert(input); // throws TraversalError
// after
if (!type.allows(input)) {
const err = type(input); // inspect per-key errors
throw new Error(`bad input: ${err.summary}`);
} Defensive patterns
Strategy: try-catch
Validate before calling
const result = type(value); // returns errors instead of throwing
if (result instanceof type.constructor // ArkType: truthy result means valid
) {} else { console.log(result.summary); } Type guard
function isValid(v: unknown): boolean { return type.allows(v); } Try / catch
try {
type.assert(value);
} catch (err) {
if (err instanceof TraversalError) {
console.error(err.errors.summary); // per-path diagnostics
} else throw err;
} Prevention
- Prefer `type(value)` or `type.allows(value)` over `assert` when input may be invalid.
- Validate all external input (API, files, env) at the boundary before use.
- Keep schemas and data shapes in sync; add tests for schema changes.
When it happens
Trigger: Calling `type.assert(value)` (or `.throw()` on an `OmpErrors` instance) when the validated value fails one or more type constraints.
Common situations: Validating untrusted JSON input (API payloads, config files) against an ArkType-compatible schema; type changes after schema updates; partially migrated data shapes.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Invalid pattern: {err}
- Destination option ${key} must be a string
- Destination option ${key} must be a finite number
- Destination option ${key} must be a boolean
- wait(...) expects milliseconds (number) or a predicate funct
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/779a49704dfa3171.
Report an issue: GitHub.