{"record":{"id":"e67e8ca24b9f5cec","repo":"toon-format/toon","slug":"result-stricterror","errorCode":null,"errorMessage":"result.strictError","messagePattern":"result\\.strictError","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"packages/toon/src/decode/decoders.ts","lineNumber":674,"sourceCode":"// `ToonDecodeError` with a `cause`, matching the direct-throw path.\nfunction resolveArrayHeader(\n  result: ArrayHeaderParseResult,\n  strict: boolean,\n): { header: ArrayHeaderInfo, inlineValues?: string } | undefined {\n  if (result.kind === 'notHeader') {\n    return undefined\n  }\n\n  if (result.kind === 'invalid') {\n    if (strict) {\n      throw new SyntaxError(result.reason)\n    }\n    return undefined\n  }\n\n  // A valid header may still carry a strict-only violation that non-strict resolves via LWW.\n  if (strict && result.strictError !== undefined) {\n    throw new SyntaxError(result.strictError)\n  }\n\n  return { header: result.header, inlineValues: result.inlineValues }\n}\n\nfunction* yieldObjectFromFields(\n  fields: readonly FieldNode[],\n  primitives: readonly JsonPrimitive[],\n): Generator<JsonStreamEvent> {\n  let cellIndex = 0\n\n  function* walkFieldGroup(nodes: readonly FieldNode[]): Generator<JsonStreamEvent> {\n    yield { type: 'startObject' }\n    for (const node of nodes) {\n      // A non-strict width mismatch leaves trailing leaf fields with no cell; they are absent, not undefined.\n      if (!node.children && cellIndex >= primitives.length) {\n        continue\n      }","sourceCodeStart":656,"sourceCodeEnd":692,"githubUrl":"https://github.com/toon-format/toon/blob/604eac266e35166bed6f5b9e3bd586e9c60a9330/packages/toon/src/decode/decoders.ts#L656-L692","documentation":"resolveArrayHeader validates a parsed array header against strict-mode rules. If the header parses but violates a strict-only constraint, the result carries a strictError string which is thrown as a SyntaxError when strict is enabled. In non-strict mode the violation is instead resolved via last-writer-wins.","triggerScenarios":"Calling decode/decodeDocument with strict:true (default) on input whose array header is parseable but violates a strict-only rule, via headerInfo/arrayHeader -> resolveArrayHeader.","commonSituations":"Hand-edited TOON documents with malformed array headers; documents from non-conforming serializers; library upgrades that introduced stricter validation.","solutions":["Fix the array header in the input so it satisfies strict-mode rules (field counts, quoting, indentation)","Decode with strict:false to tolerate the violation via LWW resolution","Read the SyntaxError message for the exact violation and correct the source document"],"exampleFix":"// before\ndecode(input) // throws SyntaxError in strict mode\n// after\nconst value = decode(input, { strict: false }) // or fix the header","handlingStrategy":"validation","validationCode":"// If it parses non-strictly, only strict rules are at risk\nlet parsed\ntry { parsed = decode(input, { strict: false }) } catch { throw new Error('Input is not valid TOON at all') }\ntry { decode(input, { strict: true }) } catch (e) { console.warn('Strict-mode violation:', e.message) }","typeGuard":"function isStrictSafe(input: string): boolean {\n  try { decode(input, { strict: true }); return true } catch { return false }\n}","tryCatchPattern":"try {\n  const value = decode(input) // strict by default\n} catch (e) {\n  if (e instanceof SyntaxError) {\n    const value = decode(input, { strict: false }) // tolerated via LWW, or surface to user\n  }\n}","preventionTips":["Generate TOON documents with encode() instead of hand-editing","Round-trip test (encode(decode(x)) === x) in CI for stored documents","Use strict:false only deliberately, and log when you do","Pin versions and read changelogs for strictness changes"],"tags":["syntax","strict-mode","decoder","toon"],"backgroundTag":"strict-mode-validation-failed","analyzedSha":"604eac266e35166bed6f5b9e3bd586e9c60a9330","analyzedAt":"2026-08-31T11:09:25.043Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}