[p5.js 2.0 Bug Report]: Friendly errors do not prevent runtime exceptions in color APIs
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 24k
- Forks
- 3.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 25
Description
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- Build process
- Unit testing
- Internationalization
- Friendly errors
- Other (specify if possible)
p5.js version
2.2.0
Web browser and version
Google Chrome Version 144.0.7559.61
Operating system
Windows 11
Steps to reproduce this
Description:
While testing p5.js 2.0 color-related functions, I noticed that several APIs emit a Friendly Error but still throw runtime exceptions (e.g. TypeError or uncaught Error), causing sketches to crash.
In p5.js, a Friendly Error is generally expected to safely handle invalid input without crashing execution. However, this behaviour is inconsistent across color APIs.
Steps:
- Run the sketch given below
- Observe that it throws an FES error but still sketch crashes
Snippet:
function setup() {
noCanvas();
let c1 = color(255, 0, 0);
let c2 = color(0, 0, 255);
// Case 1: lerpColor crashes after friendly error
console.log(lerpColor(null, c2, 0.5));
// Case 2: invalid color string crashes
background("");
}
Observed Behaviour
- Friendly Error is logged
- Sketch then crashes with:
- TypeError: Cannot read properties of null
- or Error: Invalid color string
Expected Behaviour
Friendly Error should:
- clearly report invalid input
- prevent runtime exceptions
- allow sketch execution to continue safely
Additional Notes
This pattern occurs in multiple color-related APIs (background, fill, stroke, color, alpha, lerpColor). Some functions correctly handle invalid input after emitting a Friendly Error, while others still throw.
I'm willing to implement a fix if this gets approved
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied setup() sketch and inspect the color API entry points named in the report: background, fill, stroke, color, alpha, and lerpColor. Compare how each handles invalid input after reporting a Friendly Error; done means the affected APIs report the error without uncaught runtime exceptions and allow sketch execution to continue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100