{"record":{"id":"7a664f3c9a06d084","repo":"nodejs/node","slug":"could-not-open-codepage-s-s","errorCode":null,"errorMessage":"Could not open codepage [%s]: %s\n","messagePattern":"Could not open codepage \\[(.+?)\\]: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deps/icu-small/source/tools/toolutil/ucbuf.cpp","lineNumber":516,"sourceCode":"        if((buf->conv==nullptr) && (buf->showWarning==true)){\n            fprintf(stderr,\"###WARNING: No converter defined. Using codepage of system.\\n\");\n        }\n        buf->remaining=fileSize-buf->signatureLength;\n        if(buf->isBuffered){\n            buf->bufCapacity=MAX_U_BUF;\n        }else{\n            buf->bufCapacity=buf->remaining+buf->signatureLength+1/*for terminating nul*/;               \n        }\n        buf->buffer=(char16_t*) uprv_malloc(U_SIZEOF_UCHAR * buf->bufCapacity );\n        if (buf->buffer == nullptr) {\n            *error = U_MEMORY_ALLOCATION_ERROR;\n            ucbuf_close(buf);\n            return nullptr;\n        }\n        buf->currentPos=buf->buffer;\n        buf->bufLimit=buf->buffer;\n        if(U_FAILURE(*error)){\n            fprintf(stderr, \"Could not open codepage [%s]: %s\\n\", *cp, u_errorName(*error));\n            ucbuf_close(buf);\n            return nullptr;\n        }\n        ucbuf_fillucbuf(buf,error);\n        if(U_FAILURE(*error)){\n            ucbuf_close(buf);\n            return nullptr;\n        }\n        return buf;\n    }\n    *error =U_FILE_ACCESS_ERROR;\n    return nullptr;\n}\n\n\n\n/* TODO: this method will fail if at the\n * beginning of buffer and the uchar to unget","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/icu-small/source/tools/toolutil/ucbuf.cpp#L498-L534","documentation":"Emitted from a defensive check near the end of ucbuf_open's setup phase: if a failure status somehow persists after buffer allocation, it prints the requested codepage name and the ICU error name (u_errorName), closes the buffer, and returns nullptr. In practice it mirrors the ucnv_open(*cp) failure path -- the requested converter name is unknown to ICU's converter registry.","triggerScenarios":"ucbuf_open called with a *cp string ICU does not recognize: a typo (\"UTG-8\", \"utf 8\"), an unsupported/unregistered alias, a MIME label not compiled in, or any name for which ucnv_open sets a failure status. Also reachable if an earlier step in the open sequence set a non-zero status that propagated here.","commonSituations":"Misspelled encoding passed on the command line / in build config; ICU built with a reduced converter set (legacy EBCDIC/Asian codepages omitted); passing a private or platform-specific alias; status not reset to U_ZERO_ERROR between ICU calls so an earlier failure is mis-attributed to the codepage.","solutions":["Use a canonical ICU converter name/alias: \"UTF-8\", \"ISO-8859-1\", \"windows-1252\", \"Shift_JIS\", etc. (verify with ucnv_openAllNames or the ICU converter guide).","Read the error name in the printed message to pinpoint the failure, then fix *cp accordingly.","If a required legacy codepage is missing, rebuild ICU with full converter data rather than substituting an approximation.","Pre-check standalone: call ucnv_open(*cp, &err) and confirm U_SUCCESS before invoking ucbuf_open, and reset status = U_ZERO_ERROR before each ICU call."],"exampleFix":"// before: typo'd name -> ucnv_open fails -> \"Could not open codepage\"\nconst char* cp = \"UTG-8\";\nUCHARBUF* b = ucbuf_open(path, &cp, true, false, &status);\n// after:\nconst char* cp = \"UTF-8\";\nUCHARBUF* b = ucbuf_open(path, &cp, true, false, &status);","handlingStrategy":"validation","validationCode":"// Standalone pre-check: does ICU know this converter name?\n#include <unicode/ucnv.h>\nbool cp_openable(const char* cp) {\n    if (!cp || !*cp) return false;\n    UErrorCode err = U_ZERO_ERROR;\n    UConverter* c = ucnv_open(cp, &err);\n    bool ok = U_SUCCESS(err) && c != nullptr;\n    if (c) ucnv_close(c);\n    return ok;\n}\n// call before ucbuf_open; bail out with a clear message if false","typeGuard":null,"tryCatchPattern":"UErrorCode status = U_ZERO_ERROR;\nconst char* cp = argv[enc_idx];\nUCHARBUF* b = ucbuf_open(path, &cp, /*showWarning=*/true, false, &status);\nif (status == U_FILE_ACCESS_ERROR || U_FAILURE(status)) {\n    // 'Could not open codepage' already printed; report and abort.\n    fprintf(stderr, \"unknown encoding '%s'; see ucnv_openAllNames()\\n\", cp);\n    return EXIT_FAILURE;\n}","preventionTips":["Whitelist canonical ICU converter names in your build config and reject anything else.","Reset status = U_ZERO_ERROR before every ICU call so an earlier failure can't be mis-blamed on the codepage.","If you need a legacy codepage, ensure your ICU build includes the full converter set.","Pre-validate *cp with ucnv_open in a unit test of your build pipeline."],"tags":["icu","codepage","converter","ucnv","toolutil"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}