nodejs/node · error
Could not open codepage [%s]: %s
Error message
Could not open codepage [%s]: %s
What it means
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.
Source
Thrown at deps/icu-small/source/tools/toolutil/ucbuf.cpp:516
if((buf->conv==nullptr) && (buf->showWarning==true)){
fprintf(stderr,"###WARNING: No converter defined. Using codepage of system.\n");
}
buf->remaining=fileSize-buf->signatureLength;
if(buf->isBuffered){
buf->bufCapacity=MAX_U_BUF;
}else{
buf->bufCapacity=buf->remaining+buf->signatureLength+1/*for terminating nul*/;
}
buf->buffer=(char16_t*) uprv_malloc(U_SIZEOF_UCHAR * buf->bufCapacity );
if (buf->buffer == nullptr) {
*error = U_MEMORY_ALLOCATION_ERROR;
ucbuf_close(buf);
return nullptr;
}
buf->currentPos=buf->buffer;
buf->bufLimit=buf->buffer;
if(U_FAILURE(*error)){
fprintf(stderr, "Could not open codepage [%s]: %s\n", *cp, u_errorName(*error));
ucbuf_close(buf);
return nullptr;
}
ucbuf_fillucbuf(buf,error);
if(U_FAILURE(*error)){
ucbuf_close(buf);
return nullptr;
}
return buf;
}
*error =U_FILE_ACCESS_ERROR;
return nullptr;
}
/* TODO: this method will fail if at the
* beginning of buffer and the uchar to ungetView on GitHub (pinned to 1b2de5e052)
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.
Example fix
// before: typo'd name -> ucnv_open fails -> "Could not open codepage" const char* cp = "UTG-8"; UCHARBUF* b = ucbuf_open(path, &cp, true, false, &status); // after: const char* cp = "UTF-8"; UCHARBUF* b = ucbuf_open(path, &cp, true, false, &status);
Defensive patterns
Strategy: validation
Validate before calling
// Standalone pre-check: does ICU know this converter name?
#include <unicode/ucnv.h>
bool cp_openable(const char* cp) {
if (!cp || !*cp) return false;
UErrorCode err = U_ZERO_ERROR;
UConverter* c = ucnv_open(cp, &err);
bool ok = U_SUCCESS(err) && c != nullptr;
if (c) ucnv_close(c);
return ok;
}
// call before ucbuf_open; bail out with a clear message if false Try / catch
UErrorCode status = U_ZERO_ERROR;
const char* cp = argv[enc_idx];
UCHARBUF* b = ucbuf_open(path, &cp, /*showWarning=*/true, false, &status);
if (status == U_FILE_ACCESS_ERROR || U_FAILURE(status)) {
// 'Could not open codepage' already printed; report and abort.
fprintf(stderr, "unknown encoding '%s'; see ucnv_openAllNames()\n", cp);
return EXIT_FAILURE;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ###WARNING: Encountered abnormal bytes while converting inp
- ###WARNING: No converter defined. Using codepage of system.
- Failed to open %s: %s\n
- Conversion failure at #%X: %s\n
- %s:%d: %s\n
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/7a664f3c9a06d084.
Report an issue: GitHub.