{"record":{"id":"d604465de317578e","repo":"toon-format/toon","slug":"invalid-escape-sequence-truncated-u-escape-at","errorCode":null,"errorMessage":"Invalid escape sequence: truncated \\u escape at \"${value.slice(i, i + 6)}\"","messagePattern":"Invalid escape sequence: truncated \\\\u escape at \"(.+?)\"","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"packages/toon/src/shared/string-utils.ts","lineNumber":86,"sourceCode":"      }\n      if (next === 'r') {\n        unescaped += CARRIAGE_RETURN\n        i += 2\n        continue\n      }\n      if (next === BACKSLASH) {\n        unescaped += BACKSLASH\n        i += 2\n        continue\n      }\n      if (next === DOUBLE_QUOTE) {\n        unescaped += DOUBLE_QUOTE\n        i += 2\n        continue\n      }\n      if (next === 'u') {\n        if (i + 6 > value.length) {\n          throw new SyntaxError(`Invalid escape sequence: truncated \\\\u escape at \"${value.slice(i, i + 6)}\"`)\n        }\n        const hex = value.slice(i + 2, i + 6)\n        if (!/^[0-9a-f]{4}$/i.test(hex)) {\n          throw new SyntaxError(`Invalid escape sequence: \\\\u must be followed by 4 hex digits, got \"${hex}\"`)\n        }\n        const codeUnit = Number.parseInt(hex, 16)\n        if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) {\n          throw new SyntaxError(`Invalid escape sequence: \\\\u${hex} is a lone surrogate. Supplementary code points MUST appear as literal UTF-8`)\n        }\n        unescaped += String.fromCodePoint(codeUnit)\n        i += 6\n        continue\n      }\n\n      throw new SyntaxError(`Invalid escape sequence: \\\\${next}`)\n    }\n\n    unescaped += value[i]","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/toon-format/toon/blob/604eac266e35166bed6f5b9e3bd586e9c60a9330/packages/toon/src/shared/string-utils.ts#L68-L104","documentation":"A \\u escape requires exactly the characters \\u plus 4 following characters. When fewer than 4 characters remain in the string after \\u, the escape is truncated and unescapeString throws this SyntaxError, including the partial text for diagnosis.","triggerScenarios":"Parsing a quoted TOON string whose escape sequence ends the string prematurely, e.g. \"\\\\u0\" or \"\\\\u12\" — i + 6 exceeds value.length.","commonSituations":"Files truncated by copy-paste limits or line-based tools; manual authoring of unicode escapes without completing them; programmatic string slicing that cut mid-escape.","solutions":["Complete the escape with all 4 hex digits (e.g. \\u0041)","Use the literal UTF-8 character instead of the \\u escape","Verify the input file is not truncated at the point of the escape"],"exampleFix":"// before (TOON input)\nlabel: \"A\\u0\"\n// after\nlabel: \"A\\u0041\"  // or label: \"AA\" with the literal character","handlingStrategy":"validation","validationCode":"function hasCompleteUnicodeEscapes(s: string): boolean {\n  return !/\\\\u(?![0-9a-fA-F]{4})/.test(s)\n}","typeGuard":null,"tryCatchPattern":"try {\n  const value = decode(input)\n} catch (e) {\n  if (e instanceof SyntaxError && e.message.includes('truncated \\\\u escape')) {\n    // log the reported slice, fix input, or re-request the source\n  }\n  throw e\n}","preventionTips":["Write literal UTF-8 characters instead of \\u escapes","Check for file truncation when inputs come from network or clipboard","Lint TOON text with a regex for malformed escapes"],"tags":["decoder","escape-sequence","unicode","syntax-error"],"backgroundTag":"invalid-escape-sequence","analyzedSha":"604eac266e35166bed6f5b9e3bd586e9c60a9330","analyzedAt":"2026-08-31T11:09:25.043Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}