-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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