Skip to content

Provide friendly error help when sketches use p5 functions outside of setup/draw #1121

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

Closed
toolness opened this issue Nov 21, 2015 · 1 comment · Fixed by #1130
Closed

Provide friendly error help when sketches use p5 functions outside of setup/draw #1121

toolness opened this issue Nov 21, 2015 · 1 comment · Fixed by #1130

Comments

@toolness
Copy link
Member

(This is basically a re-post of #1106 (comment), which was a comment in a closed issue that might have gone unnoticed.)

@lmccart wrote:

no p5 functions work outside of setup/draw... if you can think of any good way to catch this error it'd be wonderful, but I haven't come up with anything yet. the main issue is that calling p5 functions before setup fails because p5 hasn't been instantiated yet (this non-automatic global binding of p5 functions is in place to support instance mode, where p5 is wrapped up in one object so as not to pollute the global namespace. so we have to wait to be sure we are working in global mode before adding all the p5 functions). so i'm not how we could catch errors when p5 isn't running? but any thoughts welcome!

It's a bit hacky, but what if we added an onerror event handler that caught errors during page load and offered help if possible?

Here's an example: http://jsbin.com/riyaco/2/edit?html,console,output

Again, it's hacky, and I'm not sure how many false positives it'd trigger...

@lmccart
Copy link
Member

lmccart commented Nov 21, 2015

hmm, interesting... I can't think of any major downsides to giving it a shot? if it seems to cause more confusion than it's worth we can always remove it.

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 a pull request may close this issue.

2 participants