Skip to content

FES: Global Error Catching #4670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 14, 2020
Merged

Conversation

akshay-99
Copy link
Member

@akshay-99 akshay-99 commented Jul 3, 2020

Resolves #4662

Changes:

  • Detect internal library errors and log accordingly
  • A simpler stack trace by filtering out the internal call details

Pending

  • Explanation for various kinds of errors and suggestions to address them
    • SyntaxErrors
    • ReferenceErrors
    • TypeErrors

image

There may be unintentional errors that happen inside the p5js library. Often these are due to wrong arguments but may sometimes be due to other reasons. There are also a bunch of intentional errors that the library can throw. These are often confusing as they point to a line inside the library and the stacktrace is filled with internal calls. These can be simplified by focusing on the lines in the sketch that led to it. As seen above, the error from the browser can be confusing and the FES can quickly inform about the relevant details.

It may be good to consider using some styling ( colours, font, etc ) to pull the focus away from the raw error of the browser and towards the simpler FES message.
image

From what I could gather, styling of log messages used to be a part of the FES until it was removed three years ago in #2141, to integrate with the web editor, which was new back then. I assume that the console on editor did not support styling of messages back then. But I tried it now, and it seems to work. https://editor.p5js.org/akshay.padte/sketches/8VFX4Fq2v

It would great if someone could give some insight as to exactly why styling was removed in the FES and the current status with the web editor.

PR Checklist

@akshay-99 akshay-99 force-pushed the global-error-catching branch from c8c88d8 to e81e664 Compare July 7, 2020 02:46
@akshay-99 akshay-99 force-pushed the global-error-catching branch from 3d08f6e to 71210f5 Compare July 8, 2020 09:35
@akshay-99 akshay-99 force-pushed the global-error-catching branch from d48b2a9 to bd31d85 Compare July 10, 2020 12:50
@akshay-99
Copy link
Member Author

akshay-99 commented Jul 10, 2020

So I think this is now ready for review. There are a few problems when running this on the web editor.

  1. The line numbers are incorrect. The web-editor concatenates all source files into about:srcdoc while running the code. So the line numbers in the error messages are relative to the top of about:srcdoc. From what I can tell, this problem has existed from as far back as p5.js 0.6.0, as seen in this sketch
    https://editor.p5js.org/akshay.padte/sketches/6fam0ePVY
    image

  2. Errors sometimes don't appear on the editor console. But they do appear on the browser console.
    This also doesn't seem to be a problem introduced in this PR. I could see this problem with p5js 1.0.0 on the web editor as well
    With 0.10.2: https://editor.p5js.org/akshay.padte/sketches/aTScY4lww
    With 1.0.0: https://editor.p5js.org/akshay.padte/sketches/11jsOhiQM
    With this PR: https://editor.p5js.org/akshay.padte/sketches/pWKI8QYZ8

Colours and styling for FES messages does seem to work on the web editor as of now. However, I decided not to enable it yet as it would be nice if someone else could explain why it was disabled in the first place. Styling can be enabled later just by the flipping this toggle.

Since there are a lot of sketches needed to test all these changes, I am posting links to the editor instead of pasting all the codes here. While reviewing please check them on the editor as well as locally.

  1. ReferenceError: "x" is not defined. (Often a mistake in scope or spelling/capitalization)
    The misspelling check runs first. The FES message in the sketch below is displayed if no close match is found in library functions.
    https://editor.p5js.org/akshay.padte/sketches/HuNUNTvvP

  2. TypeError: "x" cannot be called as a function
    https://editor.p5js.org/akshay.padte/sketches/DYYCqX77u
    https://editor.p5js.org/akshay.padte/sketches/ey5iJKG9C

  3. SyntaxError: invalid token ( often a result of copying code from some other place )
    https://editor.p5js.org/akshay.padte/sketches/KOoLFGWMh

  4. SyntaxError: unexpected token ( often a simple typo )
    https://editor.p5js.org/akshay.padte/sketches/w9vtsIRHr

  5. An unexpected error inside the p5 library
    https://editor.p5js.org/akshay.padte/sketches/FBZiY5E2s

  6. An error inside the p5 library due to a non loadX method used in preload.
    https://editor.p5js.org/akshay.padte/sketches/no9oCLtHB

@akshay-99 akshay-99 marked this pull request as ready for review July 10, 2020 14:59
@stalgiag
Copy link
Contributor

Great! This is really exciting.

This is a big one so I will review over the next few days. If I remember correctly from your schedule, your next goal isn't dependent on this so feel free to jump into that while I find time to review this. If I am incorrect about scheduling, let me know, and I will expedite the review.

@akshay-99
Copy link
Member Author

Yes I can work on the next thing while this gets reviewed

Copy link
Contributor

@stalgiag stalgiag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Few questions and suggestions inline.

@akshay-99 akshay-99 force-pushed the global-error-catching branch from 9a31ee0 to b522269 Compare July 13, 2020 19:57
@akshay-99
Copy link
Member Author

akshay-99 commented Jul 13, 2020

@stalgiag I have pushed the changes. I also removed a redundant explanatory comment from a test case as the test above it also had the same comment.

@akshay-99
Copy link
Member Author

Errors sometimes don't appear on the editor console. But they do appear on the browser console.
This also doesn't seem to be a problem introduced in this PR. I could see this problem with p5js 1.0.0 on the web editor as well
With 0.10.2: https://editor.p5js.org/akshay.padte/sketches/aTScY4lww
With 1.0.0: https://editor.p5js.org/akshay.padte/sketches/11jsOhiQM
With this PR: https://editor.p5js.org/akshay.padte/sketches/pWKI8QYZ8

So I did a little digging on this. The reason the web editor cannot display errors in the editor-console with p5.js 1.0.0 is because of the fact that in 1.0.0, setup and all other things from it happen inside a Promise. The web editor probably listens for errors on the window and copies them to the editor-console whenever they happen. But this listener cannot listen to errors which happen inside Promises.
In 1.0.0
image

In 0.10.2
image

@stalgiag stalgiag merged commit 03524f6 into processing:main Jul 14, 2020
@stalgiag
Copy link
Contributor

Amazing addition @akshay-99 thanks for the hard work! Will you open an issue about the promise-based errors not posting to the editor console? You can open it on this repo and if we decide the change needs to happen on the editor side we can transfer it.

Very excited to have these friendly messages for global errors :-D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FES: Friendly messages for global errors
2 participants