{"record":{"id":"cceb3de937da2559","repo":"nodejs/node","slug":"failed-to-prepare-dictionary-s-n","errorCode":null,"errorMessage":"failed to prepare dictionary [%s]\\n","messagePattern":"failed to prepare dictionary \\[(.+?)\\]\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deps/brotli/c/tools/brotli.c","lineNumber":937,"sourceCode":"    fclose(f);\n    return BROTLI_FALSE;\n  }\n  bytes_read = fread(buffer, sizeof(uint8_t), context->dictionary_size, f);\n  if (bytes_read != context->dictionary_size) {\n    free(buffer);\n    fprintf(stderr, \"failed to read dictionary [%s]: %s\\n\",\n            PrintablePath(context->dictionary_path), strerror(errno));\n    fclose(f);\n    return BROTLI_FALSE;\n  }\n  fclose(f);\n  context->dictionary = buffer;\n  if (command == COMMAND_COMPRESS) {\n    context->prepared_dictionary = BrotliEncoderPrepareDictionary(\n        BROTLI_SHARED_DICTIONARY_RAW, context->dictionary_size,\n        context->dictionary, BROTLI_MAX_QUALITY, NULL, NULL, NULL);\n    if (context->prepared_dictionary == NULL) {\n      fprintf(stderr, \"failed to prepare dictionary [%s]\\n\",\n              PrintablePath(context->dictionary_path));\n      return BROTLI_FALSE;\n    }\n  }\n  return BROTLI_TRUE;\n}\n\nstatic BROTLI_BOOL NextFile(Context* context) {\n  const char* arg;\n  size_t arg_len;\n\n  /* Iterator points to last used arg; increment to search for the next one. */\n  context->iterator++;\n\n  context->input_file_length = -1;\n\n  /* No input path; read from console. */\n  if (context->input_count == 0) {","sourceCodeStart":919,"sourceCodeEnd":955,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/brotli/c/tools/brotli.c#L919-L955","documentation":"`BrotliEncoderPrepareDictionary()` returned NULL when called during `ReadDictionary` (only in the compress path, `command == COMMAND_COMPRESS`). The dictionary data was read into memory successfully, but the encoder's internal preprocessing of the raw dictionary failed. This is a library-level failure, not a file I/O issue.","triggerScenarios":"Internal encoder allocation failure while building the prepared dictionary structure; the dictionary data is corrupt or contains patterns the encoder cannot preprocess; a version mismatch between the brotli library and the tool.","commonSituations":"Using a malformed or empty (zero-byte-sized-but-not-caught) dictionary; memory pressure during dictionary preparation; a custom/patched brotli build with an encoder bug.","solutions":["Verify the dictionary file is a valid raw byte sequence and not corrupted.","Check for available memory and reduce concurrent memory usage.","Rebuild brotli from a known-good source tree and retry.","Test with a small known dictionary to isolate whether the issue is dictionary-specific."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Cannot fully validate at the caller level — this is a library-internal failure.\n// Best pre-check: ensure the dictionary is well-formed.\n#include <stdbool.h>\n\nbool dictionary_likely_valid(const char *path) {\n    // Check file exists, is regular, is within size limits, and is non-empty.\n    // A zero-byte dictionary that passes FileSize will still fail PrepareDictionary.\n    struct stat st;\n    if (stat(path, &st) != 0) return false;\n    return S_ISREG(st.st_mode) && st.st_size > 0;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Test with a small known-good dictionary to isolate dictionary-specific issues.","Keep brotli library and tool versions in sync to avoid API mismatches.","Report persistent failures upstream with a minimal reproducing dictionary."],"tags":["dictionary","encoder","library-error","brotli"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}