processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.16k stars 3.23k forks source link

Decoupling the Friendly Error System to a standalone package #5629

Open willmartian opened 2 years ago

willmartian commented 2 years ago

Increasing Access

I believe the Friendly Error System increases access by helping novice users recover from coding errors. Decoupling the Friendly Error System to a standalone package might further increase access in other projects.

Most appropriate sub-area of p5.js?

Feature enhancement details

I have been been doing some early experimentation with a refactor of the Friendly Error System that works as a standalone package.

Decoupling the FES from p5.js would allow it to be used in other projects. I imagine other projects that are popular with beginners, such as ml5.js and Phaser, could benefit from this.

The FES could be instantiated with a project specific config.

export const fes = new FriendlyErrorSystem({
  jsdoc: './jsdoc.json', // JSDoc JSON output for your project
  preamble: 'You are using the FES 🚀',
  prefix: 'FES 🚀: ',
  errors: {
    en: {
      // ...
    },
    es: {
      // ...
    },
    // ...
  }
});

Example parameter validation:

import { fes } from "...";

/**
 * Logs hello to the user
 * @param {String} name 
 * @returns {void}
 */
function helloWorld(name) {
  fes.validate(arguments);
  console.log(`Hello ${name}!`);
}

// This would throw a friendly error due to a improper parameter. 
helloWorld({});

Any thoughts on whether this is worth further effort/tinkering? If a decoupled package of the FES existed with feature parity to the existing FES within p5.js, would it be worth migrating p5.js to use it? Is the FES less useful for projects that don't heavily use the global namespace, like p5.js does (disregarding instance mode)?

limzykenneth commented 2 years ago

I think this is a great idea and should be something we work towards. At the same time I can see there probably will need to be quite a bit of effort to get something working well enough for general use, which is to say I think it is something good for a GSoC or Processing Fellowship project.

Ayush23Dash commented 11 months ago

I worked on trying to Decouple FES from P5 and the following was my Decoupling Approach(as per discussion with @nbriz !)

"browserify": {
    "transform": [
      [
        "babelify",
        {
          "presets": [
            "@babel/preset-env"
          ]
        }
      ]
    ]
  }

My further approach on Decoupling would have been creating a npm package for FES and import it directly in package.json. However, with this approach we needed to consider taking care of external imports(given below) in FES files from p5.js : import {translator} from ‘../internationalization’ import * as constants from ‘../constants’ const dataDoc = require(‘../../../docs/parameterData.json’) import main

However, since this approach requires files from p5.js, so as per discussion with @nbriz and @almchung , we won’t be doing Decoupling as of now.

limzykenneth commented 11 months ago

Browserify should be applying the transforms when transpiling already, we can revisit the configuration in the future if needed.

An approach to decoupling can possibly be looking into a more generalized API for any generic library to hook into FES so instead of importing symbols, they can be passed through code instead. I'll defer to your prioritization whether this is something you want to investigate at this stage or not but thanks for looking into it anyway.