{"record":{"id":"b25af343920f9958","repo":"nodejs/node","slug":"toolutil-getcptriesize-error-umutablecptrie-build","errorCode":null,"errorMessage":"toolutil/getCPTrieSize error: umutablecptrie_buildImmutable() failed: %s\n","messagePattern":"toolutil/getCPTrieSize error: umutablecptrie_buildImmutable\\(\\) failed: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deps/icu-small/source/tools/toolutil/toolutil.cpp","lineNumber":135,"sourceCode":"        uint32_t oldValue;\n        UChar32 rangeEnd = umutablecptrie_getRange(\n            mutableCPTrie, start, UCPMAP_RANGE_NORMAL, 0, nullptr, nullptr, &oldValue);\n        if (rangeEnd > end) {\n            rangeEnd = end;\n        }\n        uint32_t newValue = (oldValue & ~mask) | value;\n        if (newValue != oldValue) {\n            umutablecptrie_setRange(mutableCPTrie, start, rangeEnd, newValue, &errorCode);\n        }\n        start = rangeEnd + 1;\n    }\n}\n\nint32_t getCPTrieSize(UMutableCPTrie *mt, UCPTrieType type, UCPTrieValueWidth valueWidth) {\n    UErrorCode errorCode = U_ZERO_ERROR;\n    UCPTrie *cpTrie = umutablecptrie_buildImmutable(mt, type, valueWidth, &errorCode);\n    if (U_FAILURE(errorCode)) {\n        fprintf(stderr,\n                \"toolutil/getCPTrieSize error: umutablecptrie_buildImmutable() failed: %s\\n\",\n                u_errorName(errorCode));\n        return -1;\n    }\n    uint8_t block[100000];\n    int32_t size = ucptrie_toBinary(cpTrie, block, sizeof(block), &errorCode);\n    ucptrie_close(cpTrie);\n    if (U_FAILURE(errorCode) && errorCode != U_BUFFER_OVERFLOW_ERROR) {\n        fprintf(stderr,\n                \"toolutil/getCPTrieSize error: ucptrie_toBinary() failed: %s (length %ld)\\n\",\n                u_errorName(errorCode), static_cast<long>(size));\n        return -1;\n    }\n    U_ASSERT((size & 3) == 0);  // multiple of 4 bytes\n    return size;\n}\n\n}  // toolutil","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/icu-small/source/tools/toolutil/toolutil.cpp#L117-L153","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate trie parameters before calling getCPTrieSize\n#include <unicode/ucptrie.h>\n#include <unicode/umutablecptrie.h>\n\nbool trieParamsAreValid(UCPTrieType type, UCPTrieValueWidth width, int32_t maxValue) {\n    // Verify value width is sufficient for the max value stored\n    switch (width) {\n        case UCPTRIE_VALUE_BITS_8:\n            return (maxValue >= 0 && maxValue <= 0xFF);\n        case UCPTRIE_VALUE_BITS_16:\n            return (maxValue >= 0 && maxValue <= 0xFFFF);\n        case UCPTRIE_VALUE_BITS_32:\n            return true;\n        default:\n            return false;\n    }\n}","typeGuard":null,"tryCatchPattern":"// Check the error code return from getCPTrieSize\nint32_t size = getCPTrieSize(mt, type, valueWidth);\nif (size < 0) {\n    fprintf(stderr, \"getCPTrieSize failed; aborting data generation\\n\");\n    // Clean up trie and return error\n    umutablecptrie_close(mt);\n    return U_INVALID_FORMAT_ERROR;\n}","preventionTips":["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."],"tags":["icu","trie","build-tool","data-generation","api-failure"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}