can1357/oh-my-pi · error · TraversalError
TraversalError
Error message
TraversalError
What it means
`type.assert(data)` runs the type against the data and, if the result is an OmpErrors collection, throws a TraversalError aggregating all traversal problems. Unlike `.allows()` or `.run()`, assert is the throwing API: failures surface as a single TraversalError rather than a returned result.
Source
Thrown at packages/omptype/src/type.ts:1021
const allows = compileAllows(this.ir);
// Shadow the shared dispatcher once this schema has its specialized check.
this.allows = allows;
return allows(data);
}
for (const step of steps) {
if (step.kind === "filter" && !step.fn(data, new Ctx(data))) return false;
}
const out = this[kBase](data);
if (out instanceof OmpErrors) return false;
for (const step of steps) {
if (step.kind === "narrow" && !step.fn(out, new Ctx(out))) return false;
}
return true;
},
assert(this: InternalType, data: unknown): unknown {
const out = this.run(data);
if (out instanceof OmpErrors) throw new TraversalError(out);
return out;
},
from(this: InternalType, data: unknown): unknown {
const out = this.run(data);
if (out instanceof OmpErrors) throw new TraversalError(out);
return out;
},
toJsonSchema(this: InternalType, options?: ToJsonSchemaOptions): Record<string, unknown> {
const ir =
options?.io === "output" ? (this.opaqueOutput ? OPAQUE_OUTPUT_IR : (this.stepOut ?? this.ir)) : this.ir;
const description = options?.description ?? this.ir.desc;
if (description === undefined) return irToJsonSchema(ir, options);
return irToJsonSchema(ir, { ...options, description });
},
};
View on GitHub (pinned to 9690622007)
Solutions
- Inspect `error.summary` / the aggregated OmpErrors for each failed path and fix the data.
- Use `T.allows(data)` or `const r = T.run(data)` for non-throwing checks first.
- Update the schema or the data so they agree; for morphs, ensure the input shape matches the morph's input type.
Example fix
// before
T.assert(data); // throws TraversalError on bad data
// after
const result = T.run(data);
if (result instanceof OmpErrors) {
console.error(result.summary);
} else {
// result is valid
} Defensive patterns
Strategy: try-catch
Validate before calling
// pre-validate without throwing
if (!T.allows(data)) {
const r = T.run(data);
// inspect r (OmpErrors) before calling assert
} Try / catch
try {
T.assert(data);
} catch (e) {
if (e instanceof TraversalError) {
// e holds aggregated OmpErrors; report per-path problems
} else throw e;
} Prevention
- Use `T.allows()`/`T.run()` in paths where invalid input is expected.
- Reserve `.assert()` for invariant checks where failure is a bug.
- Log the error's per-path summary to fix data quickly.
When it happens
Trigger: Calling `T.assert(data)` where data fails any validation constraint — wrong primitive type, missing required prop, failed morph/pipe, out-of-bounds number, etc.
Common situations: Validating external input (HTTP bodies, CLI args, config) at runtime; asserting a value whose shape drifted after a schema change; test assertions on fixture data.
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
- Unsupported language '{value}'. Supported: {}
- Unable to infer language from file extension: {}. Specify `l
- Invalid pattern: {err}
- Failed to load tree-sitter language: {err}
- err.to_string() (invalid glob pattern)
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/795d60852c8a0706.
Report an issue: GitHub.