processing / processing/p5.js

[p5.js 2.0 Bug Report]: Friendly errors do not prevent runtime exceptions in color APIs

Open
#8,458 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:Color p5.js 2.0+
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:
  1. Run the sketch given below
  2. 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

  1. Friendly Error is logged
  2. Sketch then crashes with:
  • TypeError: Cannot read properties of null
  • or Error: Invalid color string

Expected Behaviour

Friendly Error should:

  1. clearly report invalid input
  2. prevent runtime exceptions
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.