toon-format/toon · error · ToonDecodeError

Blank lines inside ${context} are not allowed in strict mode

Error message

Blank lines inside ${context} are not allowed in strict mode

What it means

Thrown by validateNoBlankLinesInRange when strict-mode decoding finds a blank line strictly between the start and end of a keyed object, tabular array, or list array block. TOON treats blank lines inside multi-line structures as structurally ambiguous in strict mode, since they could merge or split blocks. The error reports the first offending blank line. Only fires when strict is true; the function returns early otherwise.

Source

Thrown at packages/toon/src/decode/validation.ts:68

  }
}

export function validateNoBlankLinesInRange(
  startLine: number,
  endLine: number,
  blankLines: BlankLineInfo[],
  strict: boolean,
  context: string,
): void {
  if (!strict)
    return

  const firstBlank = blankLines.find(
    blank => blank.lineNumber > startLine && blank.lineNumber < endLine,
  )

  if (firstBlank) {
    throw new ToonDecodeError(
      `Blank lines inside ${context} are not allowed in strict mode`,
      { line: firstBlank.lineNumber },
    )
  }
}

// #endregion

// #region Row classification helpers

/** Checks if a line is a data row (vs a key-value pair) in a tabular array. */
export function isDataRow(content: string, delimiter: Delimiter): boolean {
  const colonPos = findUnquotedChar(content, COLON)
  const delimiterPos = findUnquotedChar(content, delimiter)

  if (colonPos === -1) {
    return true
  }

View on GitHub (pinned to 604eac266e)

Solutions

  1. Remove the blank line(s) inside the array/object block
  2. Decode with { strict: false } if blank-line tolerance is acceptable
  3. Run a preprocessor that strips blank lines within indentation blocks before decoding

Example fix

// before
items[2]:
  - a

  - b
// after
items[2]:
  - a
  - b
Defensive patterns

Strategy: validation

Validate before calling

const clean = input.split('\n').filter((l, i, a) => !(l.trim() === '' && insideBlock(a, i))).join('\n')

Try / catch

try { decode(input, { strict: true }) } catch (e) { if (e instanceof ToonDecodeError && e.message.includes('Blank lines inside')) console.error('blank line at line', e.line?.lineNumber, '— strip blank lines inside blocks') }

Prevention

When it happens

Trigger: Decoding TOON input with strict:true containing an empty line inside a keyed object, tabular array body, or list-form array body (decodeKeyedObject / decodeTabularArray / decodeListArray).

Common situations: Humans hand-editing TOON for readability and inserting separator blank lines; templating tools or editors that add trailing blank lines between blocks; concatenating chunks that each end with a newline.

Related errors


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