mozilla/pdf.js · error · FormatError

Invalid dictionary name ${name}"

Error message

Invalid dictionary name ${name}"

What it means

Thrown by CFFDict.getByName when called with a name absent from the dictionary's nameToKeyMap. Note the message string has a quoting typo (`Invalid dictionary name ${name}"` is missing its opening quote and untemplatized). Like setByName, this is an internal API contract violation, not reachable from ordinary PDF input.

Source

Thrown at src/core/cff_parser.js:1280

    }
    this.values[key] = value;
    return true;
  }

  setByName(name, value) {
    if (!(name in this.nameToKeyMap)) {
      throw new FormatError(`Invalid dictionary name "${name}"`);
    }
    this.values[this.nameToKeyMap[name]] = value;
  }

  hasName(name) {
    return this.nameToKeyMap[name] in this.values;
  }

  getByName(name) {
    if (!(name in this.nameToKeyMap)) {
      throw new FormatError(`Invalid dictionary name ${name}"`);
    }
    const key = this.nameToKeyMap[name];
    if (!(key in this.values)) {
      return this.defaults[key];
    }
    return this.values[key];
  }

  removeByName(name) {
    delete this.values[this.nameToKeyMap[name]];
  }

  static createTables(layout) {
    const tables = {
      keyToNameMap: {},
      nameToKeyMap: {},
      defaults: {},
      types: {},

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Use only names that exist in the relevant CFF*DictLayout table.
  2. Prefer hasName() before getByName() if the name may be absent.
  3. Fix the quoting typo in the message if you are patching pdf.js (missing opening quote and missing template literal).

Example fix

// before
const v = dict.getByName('SomeOp'); // throws if unregistered

// after
if (dict.hasName('SomeOp')) {
  const v = dict.getByName('SomeOp');
} else {
  // fall back to a default or skip
}
Defensive patterns

Strategy: validation

Validate before calling

// Use hasName before getByName to avoid the throw.
function safeGetByName(dict, name) {
  if (!dict.hasName(name)) {
    return undefined; // or a caller-supplied default
  }
  return dict.getByName(name);
}

Type guard

function isValidCFFDictName(dict, name) {
  return typeof name === 'string' && name in dict.nameToKeyMap;
}

Try / catch

try {
  v = dict.getByName(name);
} catch (e) {
  // Unregistered name; internal API misuse.
  v = undefined;
}

Prevention

When it happens

Trigger: Internal code calls `dict.getByName('UnknownName')` for a name not in the dict's layout table. Indicates a programming error in code reading CFF dictionary values.

Common situations: A pdf.js patch referencing an operator name that was never registered in the layout table; typos in name strings passed to getByName; stale code after a layout table rename.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/6d758e460474c5ad. Report an issue: GitHub.