Skip to content

Revamp the Friendly Error System (FES) for p5.js 2.0 (detailed description)

Raphaël de Courville edited this page Apr 30, 2024 · 1 revision

Overview

The p5.js Friendly Error System (FES) enhances the development and debugging experience in p5.js with simplified error messages. With the upcoming p5.js 2.0 release, significant updates are required to align FES with the new system architecture. This project presents an opportunity for applicants to make a meaningful impact on a critical component of p5.js, which is particularly beneficial for new coders and enhances the experience for millions of users.

Description

The p5.js Friendly Error System (FES) consists of many different parts that each seeks to solve one unified problem: to make developing and debugging p5.js sketches easier and friendlier. This is done mainly through runtime checks of parameter types, printing additional error messages as it happens, and identifying common errors such as typos. With some of the architectural changes as part of upcoming p5.js 2.0 release, some aspects of FES are not fully compatible with the updates.

One such task is identification of accidentally overridden p5.js functions and constants. Currently, this works by checking if accessing these variables in the scope of the user's code throws an error. Due to the new bundling process, the scope of the user's code and the library's internals is the same, so a new detection method is needed. Since we still have the ability to fetch the user's source code as a string, a promising approach would be to use a JavaScript parser such as Acorn to find all variable and function declarations and check that there are no naming conflicts, or exploring other possible code analysis tools to leverage. This method may also be helpful in detecting things like uses of p5.js methods outside of setup and draw. A subtask would be to identify ways this method can be extended, weighing the benefits and tradeoffs of using this over the existing implementation.

Another task is to update how FES checks parameters to functions. Currently, when a p5.js constant is required (such as CLOSE as a parameter to endShape()), FES needs to check the description of each parameter in the documentation to find all-caps words, assuming those to be the possible options. This means that we end up including the documentation for all parameters in the unminified version of p5.js. We have started the process of replacing generic uses of Constant as a parameter type with more specific types, e.g. (BLEND|MULTIPLY|ADD) for blendMode(). We need to verify that FES still correctly detects errors in constants, and eliminate the now-unnecessary information included in the build to minimize the bundle size. This part of FES also does not do parameter checks for all functions, with functions that support complex overloading not being fully supported. A potential rethink of how this feature works is required.

Potential additional features/enhancements for FES are:

  1. Be easier to implement throughout the codebase and fully enable its use by addon libraries.
  2. Be able to catch errors that do not originate from p5.js itself and provide friendly errors.
  3. Expanding and completing the internationalization feature (through error message translations) of FES.

Research should be done into these features for feasibility but full implementation is optional depending on feasibility.

Please refer to p5.js Contributor Guidelines, Steward Guidelines, p5.js Friendly Error System (FES) Intro Doc, and Friendly Errors System Contribution Guide for more details.

Expected outcomes

Revamp Friendly Error System (FES) and merge the code into the p5.js 2.0 GitHub branch that can catch and warn users when they run into common errors.

Skills required

Strong experience with JavaScript, p5.js, and GitHub Workflows.