Skip to content
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

Friendly error messages for syntax errors #97

Open
shiffman opened this issue Jan 7, 2016 · 3 comments
Open

Friendly error messages for syntax errors #97

shiffman opened this issue Jan 7, 2016 · 3 comments

Comments

@shiffman
Copy link

shiffman commented Jan 7, 2016

In class today when writing objects and constructor functions, the console would not show a syntax error, but rather show a "no p5" error instead. This came up even with some small things like a missing comma or a + instead of = etc. Unfortunately I wasn't able to track all of them, but there is one that produces the problem. The JS error would be undefined is not a function.

var test = {
  x: 200,
  y: 200,
  show: function() {
    ellipse(this.x, this.y, 100, 100);
  }
}

function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(0);
  test.sho();    // ERROR IS HERE!
}
@therewasaguy
Copy link
Owner

"no p5" happens here at the moment the sketch loads, if an error occurs within a function like draw or setup that is triggered by p5 itself.

Instead of saying "no p5" which is not very helpful, we can see what caused the error and provide a more useful error message.

@therewasaguy
Copy link
Owner

Now it throws a proper error message

118be84#diff-bdf2da6adcfb8d4a4d7a170c700937d3

...but the line number is off and the message could be friendlier.

@therewasaguy
Copy link
Owner

We should be printing the second item in the Error stack trace. We could use error.stack but that is not going to work across all browsers. This library may help:

https://github.com/stacktracejs/stacktrace.js

@therewasaguy therewasaguy changed the title "no p5" error instead of proper error message Friendly error messages Feb 2, 2016
@therewasaguy therewasaguy changed the title Friendly error messages Friendly error messages for syntax errors Feb 2, 2016
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

No branches or pull requests

2 participants