Revamp the Friendly Error System for p5.js 2.0

Hi everyone! My name is Miaoye Que, and I’m one of the pr05 grantees in the inaugural cohort of the pr05 program. My project is Revamp the Friendly Error System for p5.js 2.0, which consisted of two major areas:

  1. Parameter Validation
  2. Detecting Accidentally Overridden Constants and Variables

I will introduce the new workflows briefly here:

  • For parameter validation, we store all the function signatures in parameterData.json (very condensed!), and use Zod, a TypeScript-first schema validation library with static type inference to create schemas for the function arguments. When there’s a mismatch between actual arguments and expected arguments, we identify the closest schema (if the function has overloads), and prints friendly error messages accordingly.
  • For detecting accidentally overridden constants and variables, we’re using a new approach to retrieve the user’s code, since the new bundling process that comes with the p5.js 2.0 upgrade puts user’s code and the library internals together. Afterwards, we leverage on acorn and acorn-walk, JavaScript parser and Abstract Syntax Tree walker to identify variables and constants that are of interest to us: those redefined when not supposed to. We generate friendly error messages for them too.

Both features are now code complete, but I have yet to integrate them into the dev-2.0 branch because it requires a new modular design and using the decorator pattern. I plan to keep working on it in November, and these new features will be released as part of the p5.js 2.0 version.

If you are interested in more details related to my project, please refer to my GitHub final report. There will be a Medium post incoming too!

If you have any questions, suggestions, or comments, please feel free to reply, send me an email at miaoye.que@gmail.com, or leave a comment on GitHub and tag me @sproutleaf.

Thank you!

5 Likes