nodejs/node · error
toolutil/getCPTrieSize error: umutablecptrie_buildImmutable(
Error message
toolutil/getCPTrieSize error: umutablecptrie_buildImmutable() failed: %s
What it means
Thrown by getCPTrieSize() when umutablecptrie_buildImmutable() fails during size calculation for a code point trie. This function is used by ICU data generation tools to determine the serialized binary size of a trie before writing it. The error includes the ICU error name from the failed build call.
Source
Thrown at deps/icu-small/source/tools/toolutil/toolutil.cpp:135
uint32_t oldValue;
UChar32 rangeEnd = umutablecptrie_getRange(
mutableCPTrie, start, UCPMAP_RANGE_NORMAL, 0, nullptr, nullptr, &oldValue);
if (rangeEnd > end) {
rangeEnd = end;
}
uint32_t newValue = (oldValue & ~mask) | value;
if (newValue != oldValue) {
umutablecptrie_setRange(mutableCPTrie, start, rangeEnd, newValue, &errorCode);
}
start = rangeEnd + 1;
}
}
int32_t getCPTrieSize(UMutableCPTrie *mt, UCPTrieType type, UCPTrieValueWidth valueWidth) {
UErrorCode errorCode = U_ZERO_ERROR;
UCPTrie *cpTrie = umutablecptrie_buildImmutable(mt, type, valueWidth, &errorCode);
if (U_FAILURE(errorCode)) {
fprintf(stderr,
"toolutil/getCPTrieSize error: umutablecptrie_buildImmutable() failed: %s\n",
u_errorName(errorCode));
return -1;
}
uint8_t block[100000];
int32_t size = ucptrie_toBinary(cpTrie, block, sizeof(block), &errorCode);
ucptrie_close(cpTrie);
if (U_FAILURE(errorCode) && errorCode != U_BUFFER_OVERFLOW_ERROR) {
fprintf(stderr,
"toolutil/getCPTrieSize error: ucptrie_toBinary() failed: %s (length %ld)\n",
u_errorName(errorCode), static_cast<long>(size));
return -1;
}
U_ASSERT((size & 3) == 0); // multiple of 4 bytes
return size;
}
} // toolutilView on GitHub (pinned to 1b2de5e052)
Solutions
- Examine the ICU error name in the message to understand the specific failure reason.
- Verify the UCPTrieType and UCPTrieValueWidth arguments match the trie's data characteristics.
- Check the trie's range assignments for overlaps or inconsistencies.
- Enable ICU debug logging or add checks before calling getCPTrieSize to validate trie state.
- Ensure the mutable trie has been fully populated with valid values before requesting its size.
Defensive patterns
Strategy: validation
Validate before calling
// Validate trie parameters before calling getCPTrieSize
#include <unicode/ucptrie.h>
#include <unicode/umutablecptrie.h>
bool trieParamsAreValid(UCPTrieType type, UCPTrieValueWidth width, int32_t maxValue) {
// Verify value width is sufficient for the max value stored
switch (width) {
case UCPTRIE_VALUE_BITS_8:
return (maxValue >= 0 && maxValue <= 0xFF);
case UCPTRIE_VALUE_BITS_16:
return (maxValue >= 0 && maxValue <= 0xFFFF);
case UCPTRIE_VALUE_BITS_32:
return true;
default:
return false;
}
} Try / catch
// Check the error code return from getCPTrieSize
int32_t size = getCPTrieSize(mt, type, valueWidth);
if (size < 0) {
fprintf(stderr, "getCPTrieSize failed; aborting data generation\n");
// Clean up trie and return error
umutablecptrie_close(mt);
return U_INVALID_FORMAT_ERROR;
} Prevention
- Validate trie data consistency before calling getCPTrieSize.
- Ensure UCPTrieType and UCPTrieValueWidth match the trie's actual data.
- Check the return value of getCPTrieSize (-1 indicates failure).
- Build the trie incrementally and test with small data sets first.
When it happens
Trigger: getCPTrieSize() is called with a mutable trie whose state is invalid for building an immutable trie — mismatched type/valueWidth parameters, overlapping or contradictory range assignments, or internal trie corruption. The function creates U_ZERO_ERROR, calls buildImmutable, and checks for failure.
Common situations: ICU data generation tools (gennorm2, genbrk, etc.) building trie-based data structures with invalid or inconsistent trie data; passing wrong UCPTrieType or UCPTrieValueWidth arguments; trie data containing conflicting values for the same code point ranges.
Related errors
- toolutil/getCPTrieSize error: ucptrie_toBinary() failed: %s
- Error generating assembly code for data.
- -1
- Error generating package data.
- Error creating data archive library file.
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/b25af343920f9958.
Report an issue: GitHub.