toon-format/toon · error · SyntaxError

Empty field name in field list

Error message

Empty field name in field list

What it means

A field list in an array header (e.g. `{a,b}`) contained an empty entry between delimiters, such as `{a,,b}` or `{,a}`. TOON requires every comma-separated entry in the field list to be a non-empty field name, so the parser rejects the header.

Source

Thrown at packages/toon/src/decode/parser.ts:224

  return { length: Number.parseInt(content, 10), delimiter, keyed }
}

/**
 * Parses the content of a field list into field entries, recursively
 * descending into nested field groups (`field{sub1,sub2}`).
 *
 * @remarks
 * Throws on empty segments, empty names, unmatched braces, and content
 * after a nested group's closing brace; callers decide strict fallthrough.
 */
export function parseFieldEntries(fieldsContent: string, delimiter: Delimiter): FieldNode[] {
  const entries = splitFieldEntries(fieldsContent, delimiter)

  return entries.map((entry) => {
    const trimmedEntry = trimSpaces(entry)
    if (!trimmedEntry) {
      throw new SyntaxError('Empty field name in field list')
    }

    const groupStart = findUnquotedChar(trimmedEntry, OPEN_BRACE)
    if (groupStart === -1) {
      return { name: parseStringLiteral(trimmedEntry) }
    }

    const namePart = trimSpaces(trimmedEntry.slice(0, groupStart))
    if (!namePart) {
      throw new SyntaxError('Missing field name before nested field group')
    }

    const groupEnd = findMatchingBrace(trimmedEntry, groupStart)
    if (groupEnd === -1) {
      throw new SyntaxError('Unmatched brace in field list')
    }
    if (groupEnd !== trimmedEntry.length - 1) {
      throw new SyntaxError('Unexpected content after nested field group')

View on GitHub (pinned to 604eac266e)

Solutions

  1. Remove the empty entry: delete extra delimiters so every entry has a name, e.g. `{a,b}` not `{a,,b}`
  2. Rename fields with empty or whitespace-only keys to non-empty names before encoding
  3. Fix the encoder/generator to skip or rename empty keys instead of emitting them
  4. Re-export the data (e.g. from CSV/JSON) ensuring all column headers are non-empty

Example fix

// before
items[3]{a,,b}:
// after
items[3]{a,b}:
Defensive patterns

Strategy: try-catch

Validate before calling

function hasEmptyFieldEntries(toonText) {
  const m = toonText.match(/\[\d+\]\{([^}]*)\}/)
  if (!m) return false
  return m[1].split(/[,;\t]/).some(f => f.trim() === '')
}

Try / catch

try {
  const value = toon.decode(text)
} catch (err) {
  if (err instanceof SyntaxError && err.message === 'Empty field name in field list') {
    // report offending header line for fixing
  } else throw err
}

Prevention

When it happens

Trigger: Decoding input whose array header field list has a doubled delimiter or a leading/trailing delimiter — e.g. `items[2]{a,,b}:`, `items[1]{,a}:`, or a trailing comma `items[2]{a,b,}:`. Reached via parseFieldEntries from parseArrayHeaderLine.

Common situations: Manual editing of TOON files that leaves a stray comma; generators that join field names with a delimiter and include an empty name (e.g. objects with an empty/whitespace key); template-based output where a column was removed but its delimiter wasn't.

Related errors


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