{"record":{"id":"f46104d5a1ca8f1b","repo":"parallax/jsPDF","slug":"invalid-argument-passed-to-uncompress","errorCode":null,"errorMessage":"Invalid argument passed to uncompress.","messagePattern":"Invalid argument passed to uncompress\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/standard_fonts_metrics.js","lineNumber":119,"sourceCode":"        }\n      }\n      vals.push(keystring + valuestring);\n    }\n    vals.push(\"}\");\n    return vals.join(\"\");\n  });\n\n  /**\n   * Uncompresses data compressed into custom, base16-like format.\n   *\n   * @public\n   * @function\n   * @param\n   * @returns {Type}\n   */\n  var uncompress = (API.__fontmetrics__.uncompress = function(data) {\n    if (typeof data !== \"string\") {\n      throw new Error(\"Invalid argument passed to uncompress.\");\n    }\n\n    var output = {},\n      sign = 1,\n      stringparts, // undef. will be [] in string mode\n      activeobject = output,\n      parentchain = [],\n      parent_key_pair,\n      keyparts = \"\",\n      valueparts = \"\",\n      key, // undef. will be Truthy when Key is resolved.\n      datalen = data.length - 1, // stripping ending }\n      ch;\n\n    for (var i = 1; i < datalen; i += 1) {\n      // - { } ' are special.\n\n      ch = data[i];","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/standard_fonts_metrics.js#L101-L137","documentation":"uncompress() is the inverse of the custom base16-like font-metrics encoding. It requires its input to be a string (the compressed payload); any non-string (object, number, null, undefined) throws 'Invalid argument passed to uncompress.' before parsing begins. This guards the parser from non-string input.","triggerScenarios":"Calling API.__fontmetrics__.uncompress() with an object, number, null, or undefined; passing already-decompressed metric data back in; loading metrics from a source that returned a parsed object instead of the raw string.","commonSituations":"Double-decompressing (feeding an object that was already uncompressed); JSON.parse-ing the payload before uncompress; null returned from a failed fetch passed straight through.","solutions":["Pass only the raw compressed string to uncompress().","Guard: if (typeof data === 'string') API.__fontmetrics__.uncompress(data);","Avoid calling uncompress on data that is already a metrics object — check its type first."],"exampleFix":"// before\nconst metrics = API.__fontmetrics__.uncompress(JSON.parse(raw)); // parse turned it into object -> throws [119]\n\n// after\nconst metrics = API.__fontmetrics__.uncompress(typeof raw === 'string' ? raw : String(raw));","handlingStrategy":"type-guard","validationCode":"function safeUncompress(data) {\n  if (typeof data !== 'string') {\n    throw new TypeError('uncompress expects a string payload');\n  }\n  return API.__fontmetrics__.uncompress(data);\n}","typeGuard":"function isCompressedString(data) { return typeof data === 'string'; }","tryCatchPattern":"try {\n  metrics = API.__fontmetrics__.uncompress(payload);\n} catch (e) {\n  if (/Invalid argument passed to uncompress/.test(e.message)) {\n    // payload was already an object — use it directly instead of uncompressing\n    metrics = payload;\n  } else throw e;\n}","preventionTips":["Pass only the raw compressed string; do not JSON.parse it first.","Do not double-process metrics that are already decompressed.","Guard with a typeof check before calling uncompress."],"tags":["font-metrics","internal","validation","type","pdf"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}