parallax/jsPDF · error · Error
Invalid arguments passed to jsPDF.triangle
Error message
Invalid arguments passed to jsPDF.triangle
What it means
Thrown by jsPDF.triangle when any of the six coordinates (x1,y1,x2,y2,x3,y3) is NaN or the style is invalid. All coordinates must be finite numbers; style must pass isValidStyle (undefined, null, 'S', 'D', 'F', 'DF', 'FD', 'f', 'f*', 'B', 'B*', 'n').
Source
Thrown at src/jspdf.js:4766
API.__private__.triangle = API.triangle = function(
x1,
y1,
x2,
y2,
x3,
y3,
style
) {
if (
isNaN(x1) ||
isNaN(y1) ||
isNaN(x2) ||
isNaN(y2) ||
isNaN(x3) ||
isNaN(y3) ||
!isValidStyle(style)
) {
throw new Error("Invalid arguments passed to jsPDF.triangle");
}
this.lines(
[
[x2 - x1, y2 - y1], // vector to point 2
[x3 - x2, y3 - y2], // vector to point 3
[x1 - x3, y1 - y3] // closing vector back to point 1
],
x1,
y1, // start of path
[1, 1],
style,
true
);
return this;
};
/**
* Adds a rectangle with rounded corners to PDF.View on GitHub (pinned to a3930ce03a)
Solutions
- Pass six finite numeric coordinates plus a valid style code.
- Map 'stroke'/'fill' to 'S'/'F' (or 'DF' for both) in your wrapper.
- Default or validate each vertex property before calling.
Example fix
// before pdf.triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, 'stroke'); // invalid style // after pdf.triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, 'S');
Defensive patterns
Strategy: validation
Validate before calling
const VALID_STYLES = [undefined, null, 'S','D','F','DF','FD','f','f*','B','B*','n'];
function safeTriangle(doc, x1,y1,x2,y2,x3,y3, style) {
if (![x1,y1,x2,y2,x3,y3].every(Number.isFinite)) throw new Error('all vertices must be finite');
return doc.triangle(x1,y1,x2,y2,x3,y3, VALID_STYLES.includes(style) ? style : 'S');
} Type guard
function isValidStyle(s) { return [undefined,null,'S','D','F','DF','FD','f','f*','B','B*','n'].includes(s); } Prevention
- Validate all six vertex coordinates before calling.
- Use PDF operator codes for style.
- Default each vertex property in your data layer.
When it happens
Trigger: Calling triangle() with a missing vertex coordinate, a non-numeric value, or an unsupported style such as 'stroke', 'outline', or a number.
Common situations: Vertex data sourced from an object with missing properties; friendly style names used instead of PDF codes; passing only five coordinates by mistake.
Related errors
- Invalid arguments passed to jsPDF.line
- Invalid arguments passed to jsPDF.lines
- Invalid arguments passed to jsPDF.rect
- Invalid arguments passed to jsPDF.roundedRect
- Invalid arguments passed to jsPDF.ellipse
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/8c199d86c1fc9760.
Report an issue: GitHub.