{"record":{"id":"46b6f9e5deb9d2b2","repo":"apple/pkl","slug":"unterminatedunicodeescapesequence","errorCode":"unterminatedUnicodeEscapeSequence","errorMessage":"Unterminated Unicode escape sequence `{0}`.\n\nUnicode escape sequences must end with `}`.","messagePattern":"Unterminated Unicode escape sequence `(.+?)`\\.\n\nUnicode escape sequences must end with `\\}`\\.","errorType":"exception","errorClass":"ParserError","httpStatus":null,"severity":"error","filePath":"pkl-parser/src/main/java/org/pkl/parser/Lexer.java","lineNumber":504,"sourceCode":"          throw lexError(\n              ErrorMessages.create(\"invalidCharacterEscapeSequence\", \"\\\\\" + (char) ch, \"\\\\\"),\n              cursor - 2,\n              2);\n    };\n  }\n\n  private Token lexUnicodeEscape() {\n    if (lookahead != '{') {\n      throw unexpectedChar(lookahead, \"{\");\n    }\n    do {\n      nextChar();\n    } while (lookahead != '}' && lookahead != EOF && Character.isLetterOrDigit(lookahead));\n    if (lookahead == '}') {\n      // consume the close bracket\n      nextChar();\n    } else {\n      throw lexError(ErrorMessages.create(\"unterminatedUnicodeEscapeSequence\", text()), span());\n    }\n    return Token.STRING_ESCAPE_UNICODE;\n  }\n\n  private Token lexIdentifier() {\n    while (isIdentifierPart(lookahead)) {\n      nextChar();\n    }\n\n    var identifierStr = text();\n    var identifier = getKeywordOrIdentifier(identifierStr);\n    return switch (identifier) {\n      case IMPORT -> {\n        if (lookahead == '*') {\n          nextChar();\n          yield Token.IMPORT_STAR;\n        } else yield Token.IMPORT;\n      }","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-parser/src/main/java/org/pkl/parser/Lexer.java#L486-L522","documentation":"A unicode escape `\\u{...}` was opened but the closing `}` was never found: the lexer scanned letters/digits after `{` and hit EOF (or a non-alphanumeric character that stopped the loop without reaching `}`). The message reports the partially-read escape text and states the sequence must end with `}`.","triggerScenarios":"lexEscape → lexUnicodeEscape: after consuming `\\u{`, the loop `while (lookahead != '}' && lookahead != EOF && isLetterOrDigit(lookahead))` exits with lookahead == EOF (or a non-alphanumeric char that is not `}`), e.g. `\"\\u{1F600\"` at end of string/file, or `\"\\u{12 34}\"` where a space breaks the scan before `}`.","commonSituations":"Copy-paste truncation cutting off the closing brace; typing `\\u{41}` and forgetting `}`; inserting a space or punctuation inside the codepoint like `\\u{1F 600}`; a template generator emitting partial escapes.","solutions":["Add the closing `}` to the unicode escape: `\\u{1F600}`.","Remove any non-alphanumeric characters (spaces, hyphens) inside the braces — codepoints are hex digits only.","If the escape is at end of file, restore the truncated file content.","If a literal `{` should follow `\\u`, escape the backslash: `\\\\u{`."],"exampleFix":"// before\nemoji = \"\\u{1F600\"\n// after\nemoji = \"\\u{1F600}\"","handlingStrategy":"validation","validationCode":"function unterminatedUnicode(src) { return /\\\\u\\{[0-9A-Fa-f]*$/.test(src) || /\\\\u\\{[^}]*\\s/.test(src); }\nif (unterminatedUnicode(src)) throw new Error('Unicode escape missing closing } or contains invalid chars');","typeGuard":"null","tryCatchPattern":"try { tokens = lexer.next(); } catch (e) { if (e.code === 'unterminatedUnicodeEscapeSequence') { console.error('Add closing } to the unicode escape'); } throw e; }","preventionTips":["Always type both braces at once when writing \\u escapes.","Keep only hex digits inside the braces, no spaces or hyphens.","Check template generators emit complete escapes.","Avoid end-of-file string content containing partial escapes."],"tags":["lexer","pkl","unicode","escape-sequence","unterminated"],"backgroundTag":"invalid-escape-sequence","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}