nodejs/node · error

failed to open dictionary file [%s]: %s\n

Error message

failed to open dictionary file [%s]: %s\n

What it means

`ReadDictionary` could not `fopen` the dictionary file specified via `--dictionary=<path>` in read-binary mode. The dictionary feature lets you supply custom shared-dictionary data for compression/decompression. The message includes the dictionary path and the errno description.

Source

Thrown at deps/brotli/c/tools/brotli.c:895

    fprintf(stderr, "setting user failed for [%s]: %s\n",
            PrintablePath(output_path), strerror(errno));
  }
}

/* Result ownership is passed to caller.
   |*dictionary_size| is set to resulting buffer size. */
static BROTLI_BOOL ReadDictionary(Context* context, Command command) {
  static const int kMaxDictionarySize =
      BROTLI_MAX_DISTANCE - BROTLI_MAX_BACKWARD_LIMIT(24);
  FILE* f;
  int64_t file_size_64;
  uint8_t* buffer;
  size_t bytes_read;

  if (context->dictionary_path == NULL) return BROTLI_TRUE;
  f = fopen(context->dictionary_path, "rb");
  if (f == NULL) {
    fprintf(stderr, "failed to open dictionary file [%s]: %s\n",
            PrintablePath(context->dictionary_path), strerror(errno));
    return BROTLI_FALSE;
  }

  file_size_64 = FileSize(context->dictionary_path);
  if (file_size_64 == -1) {
    fprintf(stderr, "could not get size of dictionary file [%s]",
            PrintablePath(context->dictionary_path));
    fclose(f);
    return BROTLI_FALSE;
  }

  if (file_size_64 > kMaxDictionarySize) {
    fprintf(stderr, "dictionary [%s] is larger than maximum allowed: %d\n",
            PrintablePath(context->dictionary_path), kMaxDictionarySize);
    fclose(f);
    return BROTLI_FALSE;
  }

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Verify the dictionary file exists and is readable: `ls -l <dict_path>`.
  2. Use an absolute path for `--dictionary=`.
  3. Confirm the dictionary file is a regular file, not a directory or device.

Example fix

// before
brotli --dictionary=dict.bin input.txt
// after
brotli --dictionary=/opt/brotli/dict.bin input.txt
Defensive patterns

Strategy: validation

Validate before calling

#include <unistd.h>
#include <stdbool.h>

bool dictionary_readable(const char *dict_path) {
    if (!dict_path) return true; // no dictionary requested
    return access(dict_path, R_OK) == 0;
}

// Before invoking brotli:
//   if (dict_path && !dictionary_readable(dict_path)) { fail_early(); }

Prevention

When it happens

Trigger: The dictionary path is wrong, the file was moved/deleted between argument parsing and the read, or the caller lacks read permission. Also: passing a directory path as the dictionary, or a broken symlink.

Common situations: Relative dictionary path resolved from an unexpected CWD; dictionary file lives in a deploy artifact that wasn't shipped; typo in the `--dictionary=` value; permissions locked down in a container.

Related errors


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