From 54e00b0104537cbd9c0afdd40418aa1ad3cd8203 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 19 Oct 2024 17:21:54 +0200 Subject: [PATCH] Catch errors when invoking `applyPath2DToCanvasRenderingContext` This way we allow the rest of the packages to be loaded successfully, such that e.g. the Node.js unit-tests work correctly. Note that this occurred after updating the `node-canvas` package to version `3.0.0-rc2`, however it's not immediately clear to me if it's a problem there or in the `path2d` package; see also nilzona/path2d-polyfill/issues/84. --- src/display/node_utils.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/display/node_utils.js b/src/display/node_utils.js index aca4ad750fad7..6c7c48cb87355 100644 --- a/src/display/node_utils.js +++ b/src/display/node_utils.js @@ -83,7 +83,11 @@ if (isNodeJS) { applyPath2DToCanvasRenderingContext && Path2D ) { - applyPath2DToCanvasRenderingContext(CanvasRenderingContext2D); + try { + applyPath2DToCanvasRenderingContext(CanvasRenderingContext2D); + } catch (ex) { + warn(`applyPath2DToCanvasRenderingContext: "${ex}".`); + } globalThis.Path2D = Path2D; } else { warn("Cannot polyfill `Path2D`, rendering may be broken.");