{"record":{"id":"42fa7596fbe0fa44","repo":"can1357/oh-my-pi","slug":"result-summary","errorCode":null,"errorMessage":"${result.summary}","messagePattern":"\\$\\{result\\.summary\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/zod.ts","lineNumber":117,"sourceCode":"\t\tcase \"sub\":\n\t\t\treturn isStringKeyIR(ir.schema.ir);\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction decorate<Out>(schema: Decoratable<Out>, optional = false): ZodLikeSchema<Out> {\n\tconst next = (inner: Decoratable<Out>, nextOptional = optional): ZodLikeSchema<Out> => decorate(inner, nextOptional);\n\tconst withObjectExtras = (extras: \"keep\" | \"reject\" | \"delete\"): ZodLikeSchema<Out> => {\n\t\tif (schema.ir.k !== \"object\") throw new OmpTypeError(\"object mode requires an object schema\");\n\t\treturn next(restrictBase(schema, { ...schema.ir, extras }));\n\t};\n\tObject.defineProperty(schema, \"isOptional\", { value: optional, enumerable: false });\n\n\treturn Object.assign(schema, {\n\t\tparse(value: unknown): Out {\n\t\t\tconst result = schema(value);\n\t\t\tif (result instanceof type.errors) throw new Error(result.summary);\n\t\t\treturn result;\n\t\t},\n\t\tsafeParse(value: unknown): ZodLikeSafeParseResult<Out> {\n\t\t\tconst result = schema(value);\n\t\t\tif (!(result instanceof type.errors)) return { success: true, data: result };\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: {\n\t\t\t\t\tmessage: result.summary,\n\t\t\t\t\tissues: result.map(issue => ({ path: [...issue.path], message: issue.problem })),\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\tmin(bound: number): ZodLikeSchema<Out> {\n\t\t\tconst ir = schema.ir;\n\t\t\tif (ir.k === \"string\" || ir.k === \"array\") {\n\t\t\t\tlengthBound(\"min\", schema, bound);\n\t\t\t\tconst min = ir.min === undefined ? bound : Math.max(ir.min, bound);","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/zod.ts#L99-L135","documentation":"The zod-compat `parse()` runs the schema and, when validation produces ArkType errors, throws a standard Error whose message is `result.summary` — a human-readable list of all validation failures. This is the compat layer's analogue of zod's ZodError: a failed assertion on the parsed input, not a library bug.","triggerScenarios":"`schema.parse(value)` where value fails any constraint: wrong type, missing required property, failed refinement, out-of-range string/number bounds.","commonSituations":"Parsing untrusted API payloads or JSON config that doesn't match the schema; schema tightened after a field became required while old data still lacks it; passing already-parsed/transformed objects with altered shapes.","solutions":["Read `err.message` — the summary lists each failed path and reason; fix the input data accordingly.","Use `safeParse()` instead to receive `{ success: false, error }` without throwing, and handle the failure branch.","Update the schema or the producer of the data so shapes align (optional fields, defaults, unions)."],"exampleFix":"// before\nconst user = UserSchema.parse(rawBody); // throws on bad payload\n// after\nconst res = UserSchema.safeParse(rawBody);\nif (!res.success) return respond(400, res.error);\nconst user = res.data;","handlingStrategy":"try-catch","validationCode":"// validate before parse by checking required fields yourself, or prefer safeParse:\nconst res = schema.safeParse(input);\nif (!res.success) {\n  // res.error / failure summary available without throwing\n}","typeGuard":"function isParseSuccess<T>(r: ZodLikeSafeParseResult<T>): r is { success: true; data: T } {\n  return r.success;\n}","tryCatchPattern":"try {\n  const value = schema.parse(payload);\n} catch (err) {\n  if (err instanceof Error && !(err instanceof TypeError)) {\n    // message is the validation summary — log/return 400 with it\n    return badRequest(err.message);\n  }\n  throw err;\n}","preventionTips":["Prefer safeParse at API boundaries so malformed payloads return 400s instead of crashing.","Keep schemas in sync with producers; mark legacy fields optional or add defaults.","Log the summary message — it names each failing path and reason."],"tags":["omptype","zod-compat","validation","parse"],"backgroundTag":"schema-validation-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}