{"record":{"id":"5a73360efac22d3f","repo":"toon-format/toon","slug":"expected-list-item-to-start-with-list-item-pref","errorCode":null,"errorMessage":"Expected list item to start with \"${LIST_ITEM_PREFIX}\"","messagePattern":"Expected list item to start with \"(.+?)\"","errorType":"exception","errorClass":"ToonDecodeError","httpStatus":null,"severity":"error","filePath":"packages/toon/src/decode/decoders.ts","lineNumber":548,"sourceCode":"  options: DecoderContext,\n): LineRule {\n  const line = yield* readLine(reader)\n  if (!line) {\n    throw new ReferenceError('Expected list item')\n  }\n\n  let afterHyphen: string\n\n  if (line.content === LIST_ITEM_MARKER) {\n    yield { type: 'startObject' }\n    yield { type: 'endObject' }\n    return\n  }\n  else if (line.content.startsWith(LIST_ITEM_PREFIX)) {\n    afterHyphen = line.content.slice(LIST_ITEM_PREFIX.length)\n  }\n  else {\n    throw new ToonDecodeError(\n      `Expected list item to start with \"${LIST_ITEM_PREFIX}\"`,\n      { line: line.lineNumber, source: line.raw },\n    )\n  }\n\n  if (!trimSpaces(afterHyphen)) {\n    yield { type: 'startObject' }\n    yield { type: 'endObject' }\n    return\n  }\n\n  if (trimSpaces(afterHyphen) === '[]') {\n    yield { type: 'startArray', length: 0 }\n    yield { type: 'endArray' }\n    return\n  }\n\n  const itemLine: ParsedLine = { ...line, content: afterHyphen }","sourceCodeStart":530,"sourceCodeEnd":566,"githubUrl":"https://github.com/toon-format/toon/blob/604eac266e35166bed6f5b9e3bd586e9c60a9330/packages/toon/src/decode/decoders.ts#L530-L566","documentation":"Every list entry line must begin with the `- ` list-item prefix. decodeListItem throws this ToonDecodeError when the line it reads at the list-item depth does not start with `- `. This keeps list syntax unambiguous.","triggerScenarios":"decodeListArray -> decodeListItem reads a line at the item depth whose content does not start with LIST_ITEM_PREFIX (`- `), e.g. a row like `a, b` or `name: x` directly under a list header.","commonSituations":"Forgetting the `- ` when typing list entries by hand; converting CSV lines into a list without the prefix; indentation confusion placing an object field at list-item depth.","solutions":["Prefix the line with `- `","Fix the indentation so non-list lines sit at the correct depth","Convert the structure to a tabular array header if rows are keyed","Use `[N]{fields}:` syntax instead of a bare list for keyed rows"],"exampleFix":"// before\ntags[2]:\n  a\n  b\n\n// after\ntags[2]:\n  - a\n  - b","handlingStrategy":"validation","validationCode":"function allListLinesPrefixed(text: string): boolean {\n  const lines = text.split('\\n').filter(l => l.trim())\n  const listIdx = lines.findIndex(l => /^ *\\[\\d+\\]\\s*:/.test(l))\n  if (listIdx === -1) return true\n  return lines.slice(listIdx + 1).every(l => !l.trim() || /^ *(- |\\[\\d+\\])/.test(l) === false ? false : true || true) // simplified: verify below\n}\n// practical check: any line under a bare list header must match /^\\s*- /","typeGuard":"function isListItemLine(line: string): boolean {\n  return line.trimStart().startsWith('- ')\n}","tryCatchPattern":"try {\n  return decode(input)\n} catch (e) {\n  if (e instanceof ToonDecodeError && e.message.includes('to start with')) {\n    throw new Error(`Line ${e.line}: list entries must begin with '- '`)\n  }\n  throw e\n}","preventionTips":["Always prefix list entries with `- ` (hyphen + space)","Use the encoder for lists instead of hand-writing them","Lint for lines inside list blocks lacking the prefix"],"tags":["toon","decoder","list","syntax"],"backgroundTag":"missing-list-item-prefix","analyzedSha":"604eac266e35166bed6f5b9e3bd586e9c60a9330","analyzedAt":"2026-08-31T11:09:25.043Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}