{"record":{"id":"a90a4b75e868ea9f","repo":"antonmedv/fx","slug":"invalid-unicode-escape-sequence-u-s","errorCode":null,"errorMessage":"Invalid Unicode escape sequence '\\u%s'","messagePattern":"Invalid Unicode escape sequence '\\\\u(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/jsonx/json.go","lineNumber":227,"sourceCode":"\tp.next()\n\tescaped := false\n\tfor {\n\t\tif escaped {\n\t\t\tescaped = false\n\t\t\tif p.strict {\n\t\t\t\tswitch p.char {\n\t\t\t\tcase 'u':\n\t\t\t\t\tvar s string\n\t\t\t\t\tfor i := 0; i < 4; i++ {\n\t\t\t\t\t\tp.next()\n\t\t\t\t\t\tif !utils.IsHexDigit(p.char) {\n\t\t\t\t\t\t\tpanic(fmt.Sprintf(\"Invalid Unicode escape sequence '\\\\u%s%c'\", s, p.char))\n\t\t\t\t\t\t}\n\t\t\t\t\t\ts += string(p.char)\n\t\t\t\t\t}\n\t\t\t\t\t_, err := strconv.ParseInt(s, 16, 32)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tpanic(fmt.Sprintf(\"Invalid Unicode escape sequence '\\\\u%s'\", s))\n\t\t\t\t\t}\n\t\t\t\tcase '\"', '\\\\', '/', 'b', 'f', 'n', 'r', 't':\n\t\t\t\tdefault:\n\t\t\t\t\tpanic(fmt.Sprintf(\"Invalid escape sequence '\\\\%c'\", p.char))\n\t\t\t\t}\n\t\t\t}\n\t\t} else if p.char == '\\\\' {\n\t\t\tescaped = true\n\t\t} else if p.char == '\"' {\n\t\t\tbreak\n\t\t} else if p.char == 0 {\n\t\t\tpanic(\"Unexpected end of input in string\")\n\t\t} else if rune(p.char) > unicode.MaxRune {\n\t\t\tpanic(fmt.Sprintf(\"Invalid character code point %d in string\", p.char))\n\t\t}\n\t\tp.next()\n\t}\n","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/antonmedv/fx/blob/4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe/internal/jsonx/json.go#L209-L245","documentation":"In strict mode, scanString read 4 hex digits after \\u but strconv.ParseInt failed — this occurs when the code point is a surrogate half used incorrectly... practically it fires when the hex string is out of the int32 range ParseInt(s,16,32) accepts (only possible with weird state) or, per the code path, when the parsed hex value cannot fit; the message shows the hex digits.","triggerScenarios":"Parse (strict) encountering '\\u' + 4 hex chars that ParseInt(s, 16, 32) rejects; with 4 valid hex digits max value 0xFFFF this is rare, but the branch guards it and reports the full hex sequence.","commonSituations":"Generated or obfuscated JSON containing unusual \\u sequences; tooling that emits escapes like \\uFFFF+ beyond intent; also hit when investigating surrogate pairs '\\uD83D\\uDE00' if surrounding validation is strict.","solutions":["Replace the raw \\u escape with the literal UTF-8 character in the input","Re-encode the document with encoding/json so all escapes are well-formed","Decode surrogate pairs correctly (two \\uXXXX halves) or use a single code point escape","If the input is machine-generated, fix the generator to emit only valid \\uXXXX (0000–FFFF) escapes"],"exampleFix":"// before\n\"\\u{1F600}\"  // invalid JS-style escape\n// after\n\"\\uD83D\\uDE00\"  // surrogate pair, or literal \"😀\"","handlingStrategy":"validation","validationCode":"// Validate hex payload of \\u escapes fits int32\nfor _, m := range unicodeEscapes.FindAllStringSubmatch(string(b), -1) {\n\tif _, err := strconv.ParseInt(m[1], 16, 32); err != nil {\n\t\treturn fmt.Errorf(\"bad unicode escape %s\", m[0])\n\t}\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n\tif r := recover(); r != nil {\n\t\tif msg, ok := r.(string); ok && strings.Contains(msg, \"Invalid Unicode escape\") {\n\t\t\terr = fmt.Errorf(\"unparseable unicode escape: %s\", msg)\n\t\t}\n\t}\n}()","preventionTips":["Emit only \\uXXXX (0000–FFFF) escapes from generators","Use literal UTF-8 characters for code points above U+FFFF","Normalize surrogate pairs before embedding escapes","Round-trip test payloads through encoding/json"],"tags":["json","unicode","escape-sequence"],"backgroundTag":"invalid-unicode-escape","analyzedSha":"4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe","analyzedAt":"2026-09-02T02:17:47.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}