upstash/context7 · error
Invalid TOML Unicode escape \\
Error message
Invalid TOML Unicode escape \\${escape}${hex} What it means
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.
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.
Example fix
// before (config.toml) args = ["--char", "\u41"] // after args = ["--char", "\u0041"]
Defensive patterns
Strategy: validation
Validate before calling
function validUnicodeEscapes(s) {
return [...s.matchAll(/\\u([0-9A-Fa-f]{0,8})/g)].every(m => m[1].length === 4) &&
[...s.matchAll(/\\U([0-9A-Fa-f]{0,8})/g)].every(m => m[1].length === 8);
}
if (!args.every(a => typeof a === 'string' && validUnicodeEscapes(a))) throw new Error('bad \u/\U escape width'); Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Invalid TOML Unicode code point U+
- Unsupported TOML escape \\
- Expected a comma or closing bracket in MCP args
- Expected a TOML array for MCP args
- MCP args must be a TOML array containing only strings
AI-assisted analysis of upstash/context7@4416fb855b (2026-09-16).
Data as JSON: /api/errors/117ba8d2ff28f8ac.
Report an issue: GitHub.
Appendix: source
Thrown at packages/cli/src/setup/toml-editor.ts:60
}
if (char !== "\\") {
value += char;
continue;
}
const escape = source[index++];
if (Object.hasOwn(TOML_BASIC_ESCAPES, escape)) {
value += TOML_BASIC_ESCAPES[escape];
continue;
}
if (escape !== "u" && escape !== "U") {
throw new Error(`Unsupported TOML escape \\${escape}`);
}
const width = escape === "u" ? 4 : 8;
const hex = source.slice(index, index + width);
if (!new RegExp(`^[0-9A-Fa-f]{${width}}$`).test(hex)) {
throw new Error(`Invalid TOML Unicode escape \\${escape}${hex}`);
}
const codePoint = Number.parseInt(hex, 16);
if (codePoint > 0x10ffff || (codePoint >= 0xd800 && codePoint <= 0xdfff)) {
throw new Error(`Invalid TOML Unicode code point U+${hex}`);
}
value += String.fromCodePoint(codePoint);
index += width;
}
throw new Error("Unterminated TOML basic string in MCP args");
}
function parseTomlLiteralString(source: string, start: number): TomlStringToken {
const endQuote = source.indexOf("'", start + 1);
if (endQuote === -1) throw new Error("Unterminated TOML literal string in MCP args");
const value = source.slice(start + 1, endQuote);
if (value.includes("\n") || value.includes("\r")) {
throw new Error("Multiline strings are not supported in MCP args");
}View on GitHub (pinned to 4416fb855b)