{"record":{"id":"c706f24737212a81","repo":"toon-format/toon","slug":"invalid-delimiter-json-stringify-delimiter-va","errorCode":null,"errorMessage":"Invalid delimiter ${JSON.stringify(delimiter)}. Valid delimiters are: comma (,), tab (\\t), pipe (|)","messagePattern":"Invalid delimiter (.+?)\\. Valid delimiters are: comma \\(,\\), tab \\(\\\\t\\), pipe \\(\\|\\)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/toon/src/shared/validation.ts","lineNumber":10,"sourceCode":"import type { Delimiter } from '../types.ts'\nimport { COMMENT_MARKER, DEFAULT_DELIMITER, DELIMITERS, LIST_ITEM_MARKER } from '../constants.ts'\nimport { isBooleanOrNullLiteral } from './literal-utils.ts'\n\nconst NUMERIC_LIKE_PATTERN = /^[+-]?\\d+(?:\\.\\d+)?(?:e[+-]?\\d+)?$/i\n\n/** Narrows an arbitrary delimiter option, shared by the library and the CLI so both report it alike. */\nexport function assertValidDelimiter(delimiter: string): asserts delimiter is Delimiter {\n  if (!(Object.values(DELIMITERS) as string[]).includes(delimiter)) {\n    throw new TypeError(`Invalid delimiter ${JSON.stringify(delimiter)}. Valid delimiters are: comma (,), tab (\\\\t), pipe (|)`)\n  }\n}\n\n/**\n * Checks if a key can be used without quotes.\n *\n * @remarks\n * Valid unquoted keys must start with a letter or underscore,\n * followed by letters, digits, underscores, or dots.\n */\nexport function isValidUnquotedKey(key: string): boolean {\n  return /^[A-Z_][\\w.]*$/i.test(key)\n}\n\n/**\n * Determines if a string value can be safely encoded without quotes.\n *\n * @remarks","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/toon-format/toon/blob/604eac266e35166bed6f5b9e3bd586e9c60a9330/packages/toon/src/shared/validation.ts#L1-L28","documentation":"assertValidDelimiter narrows a delimiter option to one of the three supported Delimiter values: comma, tab, or pipe. Any other string — including multi-character, empty, or numeric-like values — throws this TypeError with the offending value JSON-stringified.","triggerScenarios":"Calling encode/decode (or resolveOptions) with `delimiter: \";\"`, `delimiter: \"\"`, `delimiter: \"::\"`, or passing a non-delimiter char via CLI --delimiter flag.","commonSituations":"Assuming arbitrary delimiters are supported; copying options from another serialization library; CLI scripts templating a delimiter from config that holds \";\" or \"| \" with whitespace.","solutions":["Use one of the supported delimiters: \",\", \"\\t\", or \"|\" (or the Delimiters constants)","Check the option value for stray whitespace or wrong characters coming from config/env","If another separator is required, transform data after encoding/decoding with standard tools"],"exampleFix":"// before\nconst opts = { delimiter: \";\" }\n// after\nconst opts = { delimiter: \",\" } // or \"\\t\" or \"|\"","handlingStrategy":"type-guard","validationCode":"const DELIMITERS = [',', '\\t', '|'] as const\ntype Delimiter = typeof DELIMITERS[number]\nfunction isValidDelimiter(d: unknown): d is Delimiter {\n  return typeof d === 'string' && (DELIMITERS as readonly string[]).includes(d)\n}","typeGuard":"function isDelimiter(d: unknown): d is ',' | '\\t' | '|' {\n  return d === ',' || d === '\\t' || d === '|'\n}","tryCatchPattern":"try {\n  const out = encode(data, { delimiter: opts.delimiter })\n} catch (e) {\n  if (e instanceof TypeError && e.message.startsWith('Invalid delimiter')) {\n    // fall back to default comma delimiter\n  }\n  throw e\n}","preventionTips":["Import and use the library's Delimiters constants instead of raw strings","Validate CLI/config delimiter input at program start","Trim whitespace from delimiter values read from env/config"],"tags":["configuration","options-validation","delimiter","typeerror"],"backgroundTag":"invalid-option-value","analyzedSha":"604eac266e35166bed6f5b9e3bd586e9c60a9330","analyzedAt":"2026-08-31T11:09:25.043Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}