{"record":{"id":"28d56698ce12d0b1","repo":"can1357/oh-my-pi","slug":"parseerror-heading-error-problem","errorCode":null,"errorMessage":"ParseError: ${heading} ${error.problem}","messagePattern":"ParseError: (.+?) (.+?)","errorType":"exception","errorClass":"OmpTypeError","httpStatus":null,"severity":"error","filePath":"packages/omptype/src/type.ts","lineNumber":623,"sourceCode":"\ttarget.resolver = source.resolver;\n\tReflect.set(target, \"$\", source.$);\n\treturn target;\n}\nfunction invalidDefault(label: string, errors: OmpErrors): never {\n\tconst error = errors[0];\n\tlet heading = label;\n\tfor (let index = 0; index < error.path.length; index++) {\n\t\tconst segment = error.path[index];\n\t\tif (typeof segment === \"number\") {\n\t\t\tif (label === \"Default\" && index === 0) heading = \"Default value\";\n\t\t\theading += ` at [${segment}]`;\n\t\t} else if (label === \"Default\" && index === 0) {\n\t\t\theading += ` ${String(segment)}`;\n\t\t} else {\n\t\t\theading += `.${String(segment)}`;\n\t\t}\n\t}\n\tthrow new OmpTypeError(`ParseError: ${heading} ${error.problem}`);\n}\n\nfunction rejectMutableStaticDefault(value: unknown): void {\n\tif (value !== null && typeof value === \"object\" && !(value instanceof Date)) {\n\t\tthrow new OmpTypeError(\"ParseError: A mutable default value must be specified as a factory\");\n\t}\n}\n\nfunction normalizeDefaults(ir: IR, seen = new WeakSet<object>()): void {\n\tif (seen.has(ir)) return;\n\tseen.add(ir);\n\tswitch (ir.k) {\n\t\tcase \"object\":\n\t\t\tfor (const prop of ir.props) {\n\t\t\t\tnormalizeDefaults(prop.val, seen);\n\t\t\t\tif (!prop.hasDefault || prop.defValidated) continue;\n\t\t\t\tlet candidate: unknown;\n\t\t\t\tlet factory = false;","sourceCodeStart":605,"sourceCodeEnd":641,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/omptype/src/type.ts#L605-L641","documentation":"omptype wraps underlying parse failures in an OmpTypeError whose message is `ParseError: <heading> <problem>`. The heading is built from the type/property path segments where the default value was being normalized (e.g. `.myProp`), and `error.problem` describes why the default expression was rejected. `invalidDefault` is invoked by `normalizeDefaults` and `.default()` when a default fails validation against its own type.","triggerScenarios":"Calling `.default(value)` with a value that does not satisfy the type, or defining an object property default that fails its own constraint (e.g. `type('number > 5').default(3)`), or a nested prop default that violates the prop type.","commonSituations":"Refactoring a type's constraints after setting defaults so the stale default no longer validates; copy-pasting defaults between fields with different types; typos like `.default('1')` on a number type.","solutions":["Read `error.problem` in the message — it states the exact constraint the default violates.","Change the default to a value that satisfies the type (e.g. `type('number>5').default(10)`).","Use a factory `.default(() => value)` if a computed or Date-valued default is intended.","Re-check the path in the heading to find which nested property's default is wrong."],"exampleFix":"// before\nconst T = type('number > 5').default(3); // ParseError\n\n// after\nconst T = type('number > 5').default(10);","handlingStrategy":"validation","validationCode":"// validate the default against the type before calling .default\nif (!T.allows(candidateDefault)) {\n  throw new Error(`default ${JSON.stringify(candidateDefault)} fails type`);\n}\nconst T2 = T.default(candidateDefault);","typeGuard":"function isValidDefault(T, value) {\n  return T.allows(value);\n}","tryCatchPattern":"try {\n  const T = type('number>5').default(3);\n} catch (e) {\n  if (e instanceof OmpTypeError && e.message.startsWith('ParseError:')) {\n    console.error(e.message); // includes path heading + problem\n  } else throw e;\n}","preventionTips":["Always check `.allows(defaultValue)` when defaults are computed dynamically.","Keep type constraints and defaults defined together so refactors update both.","Prefer factories for computed defaults to avoid stale literal values."],"tags":["parse-error","default-value","validation"],"backgroundTag":"invalid-default-value","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}