{"record":{"id":"a2437cd5f7e7479b","repo":"upstash/context7","slug":"invalid-toml-unicode-code-point-u-hex","errorCode":null,"errorMessage":"Invalid TOML Unicode code point U+${hex}","messagePattern":"Invalid TOML Unicode code point U\\+(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/setup/toml-editor.ts","lineNumber":64,"sourceCode":"    }\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  }\n  return { value, start, end: endQuote + 1 };\n}\n\nfunction parseTomlStringArray(","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/upstash/context7/blob/4416fb855b8f752be735e34f943b5d0762701aad/packages/cli/src/setup/toml-editor.ts#L46-L82","documentation":"Thrown by parseTomlBasicString when a syntactically valid \\uXXXX or \\UXXXXXXXX escape decodes to a code point that is not a valid Unicode scalar value: above U+10FFFF or within the surrogate range U+D800–U+DFFF. String.fromCodePoint would throw a RangeError on such values, so the parser rejects them first with this clearer message.","triggerScenarios":"A TOML basic string in MCP args contains an escape like \\uD800 (surrogate half), \\uDFFF, or \\U00110000 (> U+10FFFF). This typically happens when someone copies a UTF-16 surrogate pair from JSON/JS source instead of the combined code point.","commonSituations":"Copy-pasting emoji or CJK characters encoded as surrogate pairs (\\uD83D\\uDE00) from JavaScript source; encoding values above the Unicode maximum; converting UTF-16 code units instead of code points.","solutions":["Replace surrogate pairs with the single combined code point (e.g. \\uD83D\\uDE00 becomes \\U0001F600).","Use a code point ≤ U+10FFFF and outside D800–DFFF.","Paste the actual character into the config file instead of an escape (TOML is UTF-8).","Remove the character or substitute a supported one."],"exampleFix":"// before (config.toml)\nargs = [\"--emoji\", \"\\uD83D\\uDE00\"]\n// after\nargs = [\"--emoji\", \"\\U0001F600\"]","handlingStrategy":"validation","validationCode":"function validCodePoints(s) {\n  return [...s.matchAll(/\\\\(?:u|U)([0-9A-Fa-f]{4,8})/g)].every(m => {\n    const cp = parseInt(m[1], 16);\n    return cp <= 0x10ffff && !(cp >= 0xd800 && cp <= 0xdfff);\n  });\n}\nif (!args.every(a => typeof a === 'string' && validCodePoints(a))) throw new Error('invalid Unicode code point in args');","typeGuard":null,"tryCatchPattern":"try { parseConfig(toml); } catch (e) { if (e.message.startsWith('Invalid TOML Unicode code point')) { console.error('Replace surrogate pairs with the combined code point:', e.message); } else throw e; }","preventionTips":["Never encode UTF-16 surrogate halves individually; use the combined code point","Keep code points ≤ U+10FFFF and outside D800–DFFF","Paste actual characters instead of escape sequences","Convert with String.fromCodePoint semantics, not UTF-16 code units"],"tags":["toml","unicode","parsing","surrogate"],"backgroundTag":"value-out-of-range","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"}