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;
}

}  // toolutil

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Examine the ICU error name in the message to understand the specific failure reason.
  2. Verify the UCPTrieType and UCPTrieValueWidth arguments match the trie's data characteristics.
  3. Check the trie's range assignments for overlaps or inconsistencies.
  4. Enable ICU debug logging or add checks before calling getCPTrieSize to validate trie state.
  5. 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

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


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/b25af343920f9958. Report an issue: GitHub.