toon-format/toon · error · SyntaxError

result.strictError

Error message

result.strictError

What it means

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.

Source

Thrown at packages/toon/src/decode/decoders.ts:674

// `ToonDecodeError` with a `cause`, matching the direct-throw path.
function resolveArrayHeader(
  result: ArrayHeaderParseResult,
  strict: boolean,
): { header: ArrayHeaderInfo, inlineValues?: string } | undefined {
  if (result.kind === 'notHeader') {
    return undefined
  }

  if (result.kind === 'invalid') {
    if (strict) {
      throw new SyntaxError(result.reason)
    }
    return undefined
  }

  // A valid header may still carry a strict-only violation that non-strict resolves via LWW.
  if (strict && result.strictError !== undefined) {
    throw new SyntaxError(result.strictError)
  }

  return { header: result.header, inlineValues: result.inlineValues }
}

function* yieldObjectFromFields(
  fields: readonly FieldNode[],
  primitives: readonly JsonPrimitive[],
): Generator<JsonStreamEvent> {
  let cellIndex = 0

  function* walkFieldGroup(nodes: readonly FieldNode[]): Generator<JsonStreamEvent> {
    yield { type: 'startObject' }
    for (const node of nodes) {
      // A non-strict width mismatch leaves trailing leaf fields with no cell; they are absent, not undefined.
      if (!node.children && cellIndex >= primitives.length) {
        continue
      }

View on GitHub (pinned to 604eac266e)

Solutions

  1. Fix the array header in the input so it satisfies strict-mode rules (field counts, quoting, indentation)
  2. Decode with strict:false to tolerate the violation via LWW resolution
  3. Read the SyntaxError message for the exact violation and correct the source document

Example fix

// before
decode(input) // throws SyntaxError in strict mode
// after
const value = decode(input, { strict: false }) // or fix the header
Defensive patterns

Strategy: validation

Validate before calling

// If it parses non-strictly, only strict rules are at risk
let parsed
try { parsed = decode(input, { strict: false }) } catch { throw new Error('Input is not valid TOON at all') }
try { decode(input, { strict: true }) } catch (e) { console.warn('Strict-mode violation:', e.message) }

Type guard

function isStrictSafe(input: string): boolean {
  try { decode(input, { strict: true }); return true } catch { return false }
}

Try / catch

try {
  const value = decode(input) // strict by default
} catch (e) {
  if (e instanceof SyntaxError) {
    const value = decode(input, { strict: false }) // tolerated via LWW, or surface to user
  }
}

Prevention

When it happens

Trigger: Calling decode/decodeDocument with strict:true (default) on input whose array header is parseable but violates a strict-only rule, via headerInfo/arrayHeader -> resolveArrayHeader.

Common situations: Hand-edited TOON documents with malformed array headers; documents from non-conforming serializers; library upgrades that introduced stricter validation.

Related errors


AI-assisted analysis of toon-format/toon@604eac266e (2026-08-31). Data as JSON: /api/errors/e67e8ca24b9f5cec. Report an issue: GitHub.