Skip to content

[p5.js 2.0 Bug Report]: p5.Image.setFrame() validation error bypasses Friendly Error System #8610

Description

@MASTERsj01

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • p5.strands
  • WebGL
  • DevOps, Build process, Unit testing
  • Internationalization (i18n)
  • Friendly Errors
  • Other (specify if possible)

p5.js version

p5.js VERSION: 2.x (main)

Web browser and version

Any

Operating system

No response

Steps to reproduce this

STEPS TO REPRODUCE THIS:

When calling setFrame() on a p5.Image (GIF) with an out-of-range frame index, the error message is displayed via raw console.log() instead of the Friendly Error System. This means the warning is not suppressed by p5.disableFriendlyErrors = true and cannot be translated via i18n.

Steps:

  1. Load an animated GIF
  2. Call setFrame() with an index greater than the total number of frames or below zero
  3. Observe the browser console — a raw console.log message appears even if FES is disabled

Snippet:

let gif;

function preload() {
  gif = loadImage('assets/my-animation.gif');
}

function setup() {
  createCanvas(100, 100);
  p5.disableFriendlyErrors = true;
  gif.setFrame(99999); // logs warning via console.log, not FES
}

Current code at src/image/p5.Image.js line 1802-1816:

setFrame(index) {
    if (this.gifProperties) {
      const props = this.gifProperties;
      if (index < props.numFrames && index >= 0) {
        props.timeDisplayed = 0;
        props.lastChangeTime = 0;
        props.displayIndex = index;
        this.drawingContext.putImageData(props.frames[index].image, 0, 0);
      } else {
        console.log(
          'Cannot set GIF to a frame number that is higher than total number of frames or below zero.'
        );
      }
    }
}

Expected behavior: The validation error should use p5._friendlyError() so it respects p5.disableFriendlyErrors and can be translated via the i18n system.

Additional context:

This is a one-file, small fix consistent with ongoing FES migration efforts across the codebase. The error message is also hardcoded in English, making it inaccessible for non-English speaking users.

I'd be happy to work on this if it gets approved!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions