processing / processing/p5.js

Error when using loadJSON should catch error and not stop the process if there is an errorCallback

Open
#5,292 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:IO Bug
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 (Web Accessibility)
  • Build tools and processes
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Friendly error system
  • Image
  • IO (Input/Output)
  • Localization
  • Math
  • Unit Testing
  • Typography
  • Utilities
  • WebGL
  • Other (specify if possible)
Details about the bug:
  • p5.js version: 1.3.1
  • Web browser and version: Firefox 88.0.1
  • Operating System: Linux
  • Steps to reproduce this:
let meta = { 
  // default value
  metadata: {}
};

function preload() {
  const uri = 'unknown.json';
  
  function onLoad(data) {
    meta.metadata = data;
  }
  
  function onError(error) {
    console.log(error);
  }
  
  loadJSON(uri, onLoad, onError);
}

function setup() {
  createcanvas(windowWidth, windowHeight);
  fill(255);
  rect(0, 0, 250, 250);
}

I am trying to fetch a file. This file can be present or not, therefore I have default data already set.

Since I provide an onError callback, It explicitly means that I wish to handle the error myself. I expect the error to be catched and passed to the onError callback, without stopping the current process.

However, here, the error is passed to onError but is not catched, so it propagates and stop everything from working.

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 at the loadJSON entry point described in the reproduction and trace how its error callback handles a missing unknown.json file. Confirm that providing onError prevents the error from stopping the process, while the callback still receives the error and the default metadata remains usable.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.