Skip to content

Add error handling for missing plotly.js optional peer dependency#70

Merged
sridhar-mani merged 2 commits intovtkjsfrom
copilot/sub-pr-64-one-more-time
Mar 11, 2026
Merged

Add error handling for missing plotly.js optional peer dependency#70
sridhar-mani merged 2 commits intovtkjsfrom
copilot/sub-pr-64-one-more-time

Conversation

Copy link

Copilot AI commented Mar 11, 2026

renderPlotlyScene dynamically imported plotly.js without a guard, causing an opaque module resolution error when the package isn't installed. Since plotly.js is an optional peer dependency, this is a valid runtime state that needs a clear user-facing message.

Changes

  • src/visualization/vizSolutionScript.js: Wrap the dynamic import("plotly.js") in try/catch; on failure, call errorLog with an actionable install instruction and return early.
let Plotly;
try {
  ({ default: Plotly } = await import("plotly.js"));
} catch {
  errorLog("plotly.js is not installed. Install it with `npm install plotly.js` to use the Plotly backend.");
  return;
}
  • package.json: Already correctly declares plotly.js as an optional peer dependency via peerDependenciesMeta — no changes required.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

… error message

Co-authored-by: sridhar-mani <165501918+sridhar-mani@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix package.json issues for Plotly conversion to VTK.js Add error handling for missing plotly.js optional peer dependency Mar 11, 2026
@sridhar-mani sridhar-mani marked this pull request as ready for review March 11, 2026 16:28
Copilot AI review requested due to automatic review settings March 11, 2026 16:28
@sridhar-mani sridhar-mani merged commit 4673a26 into vtkjs Mar 11, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds clearer runtime handling when the optional Plotly backend is selected but plotly.js is not installed, preventing opaque dynamic-import resolution errors.

Changes:

  • Wrap dynamic import("plotly.js") in try/catch inside renderPlotlyScene, log an actionable message, and return early on failure.
  • Update package-lock.json metadata to include plotly.js in peer dependencies / optional peer metadata.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/visualization/vizSolutionScript.js Adds guarded dynamic import with user-facing error logging for missing optional Plotly dependency.
package-lock.json Updates lockfile peer dependency metadata (notably plotly.js) and includes broader lockfile regeneration changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +299 to +301
} catch {
errorLog("plotly.js is not installed. Install it with `npm install plotly.js` to use the Plotly backend.");
return;
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch here will treat any failure to load plotly.js as “not installed” and then silently return. This can mislead users if plotly.js is installed but fails to evaluate (e.g., bundler/runtime incompatibility) or if the import fails for a different reason. Consider capturing the error (catch (err)) and only showing the install instruction for module-not-found cases; otherwise include the underlying error (or rethrow) so real load errors aren’t masked.

Suggested change
} catch {
errorLog("plotly.js is not installed. Install it with `npm install plotly.js` to use the Plotly backend.");
return;
} catch (err) {
const message = err && typeof err === "object" && "message" in err ? err.message : String(err);
const isModuleNotFound =
err && typeof err === "object" && err.code === "MODULE_NOT_FOUND"
|| (typeof message === "string"
&& (message.includes("Cannot find module 'plotly.js'")
|| message.includes("Cannot find package 'plotly.js'")
|| message.includes("Cannot find module \"plotly.js\"")
));
if (isModuleNotFound) {
errorLog("plotly.js is not installed. Install it with `npm install plotly.js` to use the Plotly backend.");
return;
}
errorLog(`Failed to load plotly.js: ${message}`);
throw err;

Copilot uses AI. Check for mistakes.
@nikoscham nikoscham deleted the copilot/sub-pr-64-one-more-time branch March 17, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants