{"record":{"id":"9d33f643fdcd5c89","repo":"toon-format/toon","slug":"unexpected-bare-token-line-outside-root-primitive","errorCode":null,"errorMessage":"Unexpected bare token line outside root primitive position","messagePattern":"Unexpected bare token line outside root primitive position","errorType":"exception","errorClass":"ToonDecodeError","httpStatus":null,"severity":"error","filePath":"packages/toon/src/decode/decoders.ts","lineNumber":139,"sourceCode":"  }\n}\n\nfunction overIndentedLineError(line: ParsedLine, expectedDepth: Depth): ToonDecodeError {\n  return new ToonDecodeError(\n    `Over-indented line: expected depth ${expectedDepth}, but found ${line.depth}`,\n    { line: line.lineNumber, source: line.raw },\n  )\n}\n\n// Both modes reject a bare token outside root primitive position, so it must not reach\n// the non-strict paths that drop an over-indented line.\nfunction assertNotScalarLine(line: ParsedLine): void {\n  const isListItem = line.content.startsWith(LIST_ITEM_PREFIX) || line.content === LIST_ITEM_MARKER\n  if (isListItem || findUnquotedChar(line.content, COLON) !== -1) {\n    return\n  }\n\n  throw new ToonDecodeError(\n    'Unexpected bare token line outside root primitive position',\n    { line: line.lineNumber, source: line.raw },\n  )\n}\n\nfunction keylessKeyedError(line: ParsedLine): ToonDecodeError {\n  return new ToonDecodeError(\n    'Keyless keyed header is only valid at the document root',\n    { line: line.lineNumber, source: line.raw },\n  )\n}\n\nfunction keylessHeaderError(line: ParsedLine): ToonDecodeError {\n  return new ToonDecodeError(\n    'Keyless array header is only valid at the document root or as a list item',\n    { line: line.lineNumber, source: line.raw },\n  )\n}","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/toon-format/toon/blob/604eac266e35166bed6f5b9e3bd586e9c60a9330/packages/toon/src/decode/decoders.ts#L121-L157","documentation":"A line that is neither a list item (`- ...`) nor contains an unquoted `key:` colon is a bare token; outside the document's single root-primitive position such lines have no valid meaning. assertNotScalarLine throws this to reject stray scalar lines inside objects/arrays. It is called from decodeDocument and decodeObjectFields.","triggerScenarios":"decodeDocument or decodeObjectFields encounters a line whose content has no unquoted colon and no list-item prefix, e.g. a value missing its key, or an unquoted string containing no colon in a nested block.","commonSituations":"Deleting a key but leaving the value on its own line; multi-line strings split without proper quoting; markdown or prose accidentally pasted into the file; a line where the colon got quoted away or removed.","solutions":["Restore the missing `key: ` prefix on the offending line","Quote the text so its colon is preserved and it parses as a value of a key","Remove the stray line if it is leftover prose/debris","If it was meant to be a list entry, prefix it with `- `"],"exampleFix":"// before\nuser:\n  Ada Lovelace\n\n// after\nuser:\n  name: Ada Lovelace","handlingStrategy":"validation","validationCode":"const bareLines = input.split('\\n')\n  .map((raw, i) => ({ raw: raw.trim(), i: i + 1 }))\n  .filter(l => l.raw && !l.raw.startsWith('- ') && !/^[^:]+:/.test(l.raw))\nif (bareLines.length) throw new Error(`Lines without key: ${bareLines.map(l => l.i).join(',')}`)","typeGuard":"function lineIsKeyedOrListItem(line: string): boolean {\n  const t = line.trim()\n  return t.startsWith('- ') || /:/.test(t)\n}","tryCatchPattern":"try {\n  return decode(input)\n} catch (e) {\n  if (e instanceof ToonDecodeError && e.message.includes('bare token')) {\n    const ln = e.line ?? 0\n    throw new Error(`Line ${ln} is missing its key; every non-list line needs 'key: value'`)\n  }\n  throw e\n}","preventionTips":["Ensure every nested line has an unquoted `key: ` prefix or `- ` prefix","Quote strings containing colons carefully; avoid stripping quotes when editing","Lint generated output for colon-less lines before decoding"],"tags":["toon","decoder","strict-mode","malformed-input"],"backgroundTag":"bare-token-line","analyzedSha":"604eac266e35166bed6f5b9e3bd586e9c60a9330","analyzedAt":"2026-08-31T11:09:25.043Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}