{"record":{"id":"e19366b7e2e49bb8","repo":"nodejs/node","slug":"illegal-utf-8-sequence-at-column-d-n","errorCode":null,"errorMessage":"Illegal utf-8 sequence at Column: %d\\n","messagePattern":"Illegal utf-8 sequence at Column: (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deps/icu-small/source/tools/escapesrc/escapesrc.cpp","lineNumber":288,"sourceCode":"#endif\n      \n      // Proceed to decode utf-8\n      const uint8_t* s = reinterpret_cast<const uint8_t*>(linestr.c_str());\n      int32_t length = linestr.size();\n      UChar32 c;\n      if(U8_IS_SINGLE((uint8_t)s[i]) && oldIllegal[s[i]]) {\n#if (U_CHARSET_FAMILY == U_EBCDIC_FAMILY)\n        linestr[pos] = old_byte; // put it back\n#endif\n        continue; // single code point not previously legal for \\u escaping\n      }\n\n      // otherwise, convert it to \\u / \\U\n      {\n        U8_NEXT(s, i, length, c);\n      }\n      if(c<0) {\n        fprintf(stderr, \"Illegal utf-8 sequence at Column: %d\\n\", static_cast<int>(old_pos));\n        fprintf(stderr, \"Line: >>%s<<\\n\", linestr.c_str());\n        return true;\n      }\n\n      size_t seqLen = (i-pos);\n\n      //printf(\"U+%04X pos %d [len %d]\\n\", c, pos, seqLen);fflush(stdout);\n\n      char newSeq[20];\n      if( c <= 0xFFFF) {\n        snprintf(newSeq, sizeof(newSeq), \"\\\\u%04X\", c);\n      } else {\n        snprintf(newSeq, sizeof(newSeq), \"\\\\U%08X\", c);\n      }\n      linestr.replace(pos, seqLen, newSeq);\n      pos += strlen(newSeq) - 1;\n    }\n  }","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/icu-small/source/tools/escapesrc/escapesrc.cpp#L270-L306","documentation":"Inside fixu8(), escapesrc walks an already-decoded UTF-8 region with U8_NEXT. If U8_NEXT returns a negative code point (U_INVALID_UTF8 / ill-formed sequence), the input file's bytes are not valid UTF-8 and the tool refuses to emit a \\u/\\U escape for them. It prints the offending column and the full line for diagnosis.","triggerScenarios":"A u8\"...\" literal contains bytes that do not form a valid UTF-8 sequence: truncated multi-byte sequences, illegal lead/continuation byte combinations, or overlong encodings. U8_NEXT sets c<0 in these cases.","commonSituations":"Source files saved in Latin-1 or another legacy encoding rather than UTF-8; binary garbage injected into a string literal; a BOM or stray byte mid-literal; editor corruption during cross-platform transfer.","solutions":["Re-save the offending source file as UTF-8 (without stray bytes) using the editor's encoding command, then rerun escapesrc.","Locate the column reported in the message, inspect the bytes, and fix or re-escape the malformed sequence in the literal.","Strip any BOM or invalid bytes from the file before feeding it to escapesrc."],"exampleFix":"// before (file is Latin-1, e.g. a non-breaking-space byte 0xA1 inside u8\"...\")\n\n// after\n// re-encode the file as UTF-8 (the byte becomes the proper 2-byte sequence)","handlingStrategy":"validation","validationCode":"// reject non-UTF-8 files before invoking escapesrc\nimport codecs\nwith open(path, 'rb') as f:\n    data = f.read()\ncodecs.decode(data, 'utf-8')  # raises UnicodeDecodeError if not valid UTF-8","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure editors and CI to enforce UTF-8 (no BOM) for all source files.","Add a `isutf8`/`iconv -f utf-8 -t utf-8` check as a pre-commit gate."],"tags":["icu","escapesrc","utf-8","encoding","validation"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}