parallax/jsPDF · error · Error
Error in function {function_name}: {message}
Error message
Error in function {function_name}: {message} What it means
This is not a distinct failure mode but the SAFE wrapper (`__safeCall`, src/jspdf.js:2489) that wraps `output()` (src/jspdf.js:3075). When any exception occurs during PDF generation, it builds a message `'Error in function <name>: <original message>'` from the stack. In a browser (`globalObject.console` present) it logs via console.error and alerts the user; it only re-throws (src/jspdf.js:2505) when there is no console — e.g. in stripped-down/embedded runtimes. So the real cause is whatever exception `e` was; this wrapper is the reporting layer.
Source
Thrown at src/jspdf.js:2505
};
var SAFE = function __safeCall(fn) {
fn.foo = function __safeCallWrapper() {
try {
return fn.apply(this, arguments);
} catch (e) {
var stack = e.stack || "";
if (~stack.indexOf(" at ")) stack = stack.split(" at ")[1];
var m =
"Error in function " +
stack.split("\n")[0].split("<")[0] +
": " +
e.message;
if (globalObject.console) {
globalObject.console.error(m, e);
if (globalObject.alert) alert(m);
} else {
throw new Error(m);
}
}
};
fn.foo.bar = fn;
return fn.foo;
};
var to8bitStream = function(text, flags) {
/**
* PDF 1.3 spec:
* "For text strings encoded in Unicode, the first two bytes must be 254 followed by
* 255, representing the Unicode byte order marker, U+FEFF. (This sequence conflicts
* with the PDFDocEncoding character sequence thorn ydieresis, which is unlikely
* to be a meaningful beginning of a word or phrase.) The remainder of the
* string consists of Unicode character codes, according to the UTF-16 encoding
* specified in the Unicode standard, version 2.0. Commonly used Unicode values
* are represented as 2 bytes per character, with the high-order byte appearing first
* in the string."View on GitHub (pinned to a3930ce03a)
Solutions
- Read the inner `<original message>` after the colon — it names the real failure (font, NaN, encryption, etc.); fix that root cause.
- Wrap `doc.output(...)` in try/catch so generation failures don't crash the host app.
- Ensure a console/global is available if you rely on the log-and-alert path.
- Validate fonts/pages/options before calling output() to avoid known failure modes.
Example fix
// before
var data = doc.output('arraybuffer'); // unhandled wrapped error
// after
try {
var data = doc.output('arraybuffer');
} catch (e) {
console.error('PDF generation failed:', e.message);
// handle gracefully
} Defensive patterns
Strategy: try-catch
Validate before calling
// No pre-API check possible (the wrapper reports arbitrary inner errors).
// Best prevention: validate inputs before output() — fonts registered, at least one page, finite coordinates.
function preflight(doc) {
if (!doc.getNumberOfPages || doc.getNumberOfPages() < 1) throw new Error('No pages');
return true;
}
preflight(doc);
var data = doc.output('arraybuffer'); Type guard
function isOutputReady(doc) {
return typeof doc.output === 'function' && doc.getNumberOfPages() > 0;
} Try / catch
try {
var data = doc.output('arraybuffer');
} catch (e) {
// e.message is 'Error in function output: <inner message>'
var inner = e.message.replace(/^Error in function [^:]+: /, '');
console.error('PDF output failed:', inner);
// recover or report inner cause to the user
} Prevention
- Always wrap doc.output() in try/catch so generation errors don't crash the app.
- Read the substring after the colon for the real root cause and fix that.
- Ensure a console/global is available if you rely on the log-and-alert path.
- Register fonts and add at least one page before calling output.
When it happens
Trigger: Any error thrown synchronously inside `doc.output(...)` (e.g. a font-not-found, a NaN in geometry, a plugin error) surfaces wrapped as `Error in function output: <msg>`; in a console-less runtime the wrapped error is re-thrown and propagates to the caller.
Common situations: Node/embedded environments where `globalObject.console` is undefined, so the error is thrown instead of logged; calling output() before any required setup (fonts, pages); a plugin throwing during the output render pass.
Related errors
- The option pdfobjectnewwindow just works in a browser-enviro
- The option pdfjsnewwindow just works in a browser-environmen
- The option dataurlnewwindow just works in a browser-environm
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/f967cc627833a781.
Report an issue: GitHub.