Add error handling for missing plotly.js optional peer dependency#70
Add error handling for missing plotly.js optional peer dependency#70sridhar-mani merged 2 commits intovtkjsfrom
Conversation
… error message Co-authored-by: sridhar-mani <165501918+sridhar-mani@users.noreply.github.com>
There was a problem hiding this comment.
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")intry/catchinsiderenderPlotlyScene, log an actionable message, and return early on failure. - Update
package-lock.jsonmetadata to includeplotly.jsin 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.
| } catch { | ||
| errorLog("plotly.js is not installed. Install it with `npm install plotly.js` to use the Plotly backend."); | ||
| return; |
There was a problem hiding this comment.
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.
| } 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; |
renderPlotlyScenedynamically importedplotly.jswithout a guard, causing an opaque module resolution error when the package isn't installed. Sinceplotly.jsis an optional peer dependency, this is a valid runtime state that needs a clear user-facing message.Changes
src/visualization/vizSolutionScript.js: Wrap the dynamicimport("plotly.js")intry/catch; on failure, callerrorLogwith an actionable install instruction and return early.package.json: Already correctly declaresplotly.jsas an optional peer dependency viapeerDependenciesMeta— 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.