{"record":{"id":"117ba8d2ff28f8ac","repo":"upstash/context7","slug":"invalid-toml-unicode-escape-escape-hex","errorCode":null,"errorMessage":"Invalid TOML Unicode escape \\\\${escape}${hex}","messagePattern":"Invalid TOML Unicode escape \\\\\\\\(.+?)(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/setup/toml-editor.ts","lineNumber":60,"sourceCode":"    }\n    if (char !== \"\\\\\") {\n      value += char;\n      continue;\n    }\n\n    const escape = source[index++];\n    if (Object.hasOwn(TOML_BASIC_ESCAPES, escape)) {\n      value += TOML_BASIC_ESCAPES[escape];\n      continue;\n    }\n    if (escape !== \"u\" && escape !== \"U\") {\n      throw new Error(`Unsupported TOML escape \\\\${escape}`);\n    }\n\n    const width = escape === \"u\" ? 4 : 8;\n    const hex = source.slice(index, index + width);\n    if (!new RegExp(`^[0-9A-Fa-f]{${width}}$`).test(hex)) {\n      throw new Error(`Invalid TOML Unicode escape \\\\${escape}${hex}`);\n    }\n    const codePoint = Number.parseInt(hex, 16);\n    if (codePoint > 0x10ffff || (codePoint >= 0xd800 && codePoint <= 0xdfff)) {\n      throw new Error(`Invalid TOML Unicode code point U+${hex}`);\n    }\n    value += String.fromCodePoint(codePoint);\n    index += width;\n  }\n  throw new Error(\"Unterminated TOML basic string in MCP args\");\n}\n\nfunction parseTomlLiteralString(source: string, start: number): TomlStringToken {\n  const endQuote = source.indexOf(\"'\", start + 1);\n  if (endQuote === -1) throw new Error(\"Unterminated TOML literal string in MCP args\");\n  const value = source.slice(start + 1, endQuote);\n  if (value.includes(\"\\n\") || value.includes(\"\\r\")) {\n    throw new Error(\"Multiline strings are not supported in MCP args\");\n  }","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/upstash/context7/blob/4416fb855b8f752be735e34f943b5d0762701aad/packages/cli/src/setup/toml-editor.ts#L42-L78","documentation":"Thrown by parseTomlBasicString when a \\u or \\U escape is followed by the wrong number of hex digits. TOML requires exactly 4 hex digits for \\u and exactly 8 for \\U; the parser validates this with a regex and throws if the digits are missing, short, or non-hex.","triggerScenarios":"A TOML basic string in MCP args contains \"\\u12\" (too short), \"\\uGHIJ\" (non-hex), or \"\\U0041\" (7 digits instead of 8) — any \\u/\\U escape whose following characters do not form exactly width valid hex digits.","commonSituations":"Copy-pasting \\uXXXX escapes from JavaScript/JSON where they are also valid but truncating them; hand-writing unicode escapes with the wrong digit count; confusion between \\u and \\U widths.","solutions":["Pad the escape to exactly 4 hex digits for \\u (e.g. \\u0041) or 8 for \\U (e.g. \\U00000041).","Use only characters 0-9 and A-F/a-f after \\u or \\U.","Drop the escape and embed the literal character directly in the (UTF-8) config file.","Use a single-quoted literal string if you meant a literal backslash-u sequence."],"exampleFix":"// before (config.toml)\nargs = [\"--char\", \"\\u41\"]\n// after\nargs = [\"--char\", \"\\u0041\"]","handlingStrategy":"validation","validationCode":"function validUnicodeEscapes(s) {\n  return [...s.matchAll(/\\\\u([0-9A-Fa-f]{0,8})/g)].every(m => m[1].length === 4) &&\n         [...s.matchAll(/\\\\U([0-9A-Fa-f]{0,8})/g)].every(m => m[1].length === 8);\n}\nif (!args.every(a => typeof a === 'string' && validUnicodeEscapes(a))) throw new Error('bad \\u/\\U escape width');","typeGuard":null,"tryCatchPattern":"try { parseConfig(toml); } catch (e) { if (e.message.startsWith('Invalid TOML Unicode escape')) { console.error('Use exactly 4 hex digits after \\u and 8 after \\U:', e.message); } else throw e; }","preventionTips":["Pad \\u escapes to 4 hex digits and \\U to 8","Only use 0-9 A-F a-f after \\u or \\U","Paste literal UTF-8 characters instead of escapes when possible","Validate TOML with a reference parser before deploying the config"],"tags":["toml","parsing","unicode","escape-sequence"],"backgroundTag":"invalid-argument-format","analyzedSha":"4416fb855b8f752be735e34f943b5d0762701aad","analyzedAt":"2026-09-16T20:28:07.148Z","contentChangedAt":"2026-09-16T20:28:07.148Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}