parallax/jsPDF · error · Error
Invalid argument passed to uncompress.
Error message
Invalid argument passed to uncompress.
What it means
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.
Source
Thrown at src/modules/standard_fonts_metrics.js:119
}
}
vals.push(keystring + valuestring);
}
vals.push("}");
return vals.join("");
});
/**
* Uncompresses data compressed into custom, base16-like format.
*
* @public
* @function
* @param
* @returns {Type}
*/
var uncompress = (API.__fontmetrics__.uncompress = function(data) {
if (typeof data !== "string") {
throw new Error("Invalid argument passed to uncompress.");
}
var output = {},
sign = 1,
stringparts, // undef. will be [] in string mode
activeobject = output,
parentchain = [],
parent_key_pair,
keyparts = "",
valueparts = "",
key, // undef. will be Truthy when Key is resolved.
datalen = data.length - 1, // stripping ending }
ch;
for (var i = 1; i < datalen; i += 1) {
// - { } ' are special.
ch = data[i];View on GitHub (pinned to a3930ce03a)
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.
Example fix
// before const metrics = API.__fontmetrics__.uncompress(JSON.parse(raw)); // parse turned it into object -> throws [119] // after const metrics = API.__fontmetrics__.uncompress(typeof raw === 'string' ? raw : String(raw));
Defensive patterns
Strategy: type-guard
Validate before calling
function safeUncompress(data) {
if (typeof data !== 'string') {
throw new TypeError('uncompress expects a string payload');
}
return API.__fontmetrics__.uncompress(data);
} Type guard
function isCompressedString(data) { return typeof data === 'string'; } Try / catch
try {
metrics = API.__fontmetrics__.uncompress(payload);
} catch (e) {
if (/Invalid argument passed to uncompress/.test(e.message)) {
// payload was already an object — use it directly instead of uncompressing
metrics = payload;
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Don't know what to do with value type ${typeof value}.
- Type of text must be string or Array. "{text}" is not recogn
- Invalid PDF Name Object: " + str + ", Only accept ASCII char
- Invalid permission: " + perm
- Invalid arguments passed to jsPDF.API.__acroform__.setBit
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/f46104d5a1ca8f1b.
Report an issue: GitHub.