{"record":{"id":"795d60852c8a0706","repo":"can1357/oh-my-pi","slug":"traversalerror","errorCode":null,"errorMessage":"TraversalError","messagePattern":"TraversalError","errorType":"exception","errorClass":"TraversalError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/type.ts","lineNumber":1021,"sourceCode":"\t\t\tconst allows = compileAllows(this.ir);\n\t\t\t// Shadow the shared dispatcher once this schema has its specialized check.\n\t\t\tthis.allows = allows;\n\t\t\treturn allows(data);\n\t\t}\n\t\tfor (const step of steps) {\n\t\t\tif (step.kind === \"filter\" && !step.fn(data, new Ctx(data))) return false;\n\t\t}\n\t\tconst out = this[kBase](data);\n\t\tif (out instanceof OmpErrors) return false;\n\t\tfor (const step of steps) {\n\t\t\tif (step.kind === \"narrow\" && !step.fn(out, new Ctx(out))) return false;\n\t\t}\n\t\treturn true;\n\t},\n\n\tassert(this: InternalType, data: unknown): unknown {\n\t\tconst out = this.run(data);\n\t\tif (out instanceof OmpErrors) throw new TraversalError(out);\n\t\treturn out;\n\t},\n\n\tfrom(this: InternalType, data: unknown): unknown {\n\t\tconst out = this.run(data);\n\t\tif (out instanceof OmpErrors) throw new TraversalError(out);\n\t\treturn out;\n\t},\n\n\ttoJsonSchema(this: InternalType, options?: ToJsonSchemaOptions): Record<string, unknown> {\n\t\tconst ir =\n\t\t\toptions?.io === \"output\" ? (this.opaqueOutput ? OPAQUE_OUTPUT_IR : (this.stepOut ?? this.ir)) : this.ir;\n\t\tconst description = options?.description ?? this.ir.desc;\n\t\tif (description === undefined) return irToJsonSchema(ir, options);\n\t\treturn irToJsonSchema(ir, { ...options, description });\n\t},\n};\n","sourceCodeStart":1003,"sourceCodeEnd":1039,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/type.ts#L1003-L1039","documentation":"`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.","triggerScenarios":"Calling `T.assert(data)` where data fails any validation constraint — wrong primitive type, missing required prop, failed morph/pipe, out-of-bounds number, etc.","commonSituations":"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.","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."],"exampleFix":"// before\nT.assert(data); // throws TraversalError on bad data\n\n// after\nconst result = T.run(data);\nif (result instanceof OmpErrors) {\n  console.error(result.summary);\n} else {\n  // result is valid\n}","handlingStrategy":"try-catch","validationCode":"// pre-validate without throwing\nif (!T.allows(data)) {\n  const r = T.run(data);\n  // inspect r (OmpErrors) before calling assert\n}","typeGuard":null,"tryCatchPattern":"try {\n  T.assert(data);\n} catch (e) {\n  if (e instanceof TraversalError) {\n    // e holds aggregated OmpErrors; report per-path problems\n  } else throw e;\n}","preventionTips":["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."],"tags":["traversal","validation","assertion"],"backgroundTag":"schema-validation-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}