p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

Should add error message when Canvas.parent couldn't be found

Open Falling10fruit opened this issue 2 years ago • 21 comments

Increasing Access

This will help beginners, especially if they're copying a project as a template.

Most appropriate sub-area of p5.js?

  • [ ] Accessibility (Web Accessibility)
  • [ ] Build tools and processes
  • [ ] Color
  • [ ] Core/Environment/Rendering
  • [ ] Data
  • [ ] DOM
  • [ ] Events
  • [X] Friendly error system
  • [ ] Image
  • [ ] IO (Input/Output)
  • [ ] Localization
  • [ ] Math
  • [ ] Unit Testing
  • [ ] Typography
  • [ ] Utilities
  • [ ] WebGL
  • [ ] Other (specify if possible)

Feature enhancement details

When the user attempts to attach the canvas to a non-existing element, a Friendly Error should appear instead, replacing the "appendbody" error

Falling10fruit avatar Mar 29 '22 15:03 Falling10fruit

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.

welcome[bot] avatar Mar 29 '22 15:03 welcome[bot]

Hi @Falling10fruit, I don't quite understand what you are referring to here in this issue, can you perhaps expand on it a bit more? Some sample code would be great as well. Thanks.

limzykenneth avatar Mar 30 '22 23:03 limzykenneth

Is it better now?

Falling10fruit avatar Mar 31 '22 01:03 Falling10fruit

Do you mean something like this:

function setup() {
  let canvas = createCanvas(400, 400);
  canvas.parent("myContainer");
}

where a container with id myContainer does not exist?

If that's the case I'm seeing the following from FES

🌸 p5.js says: An error with message "p is null" occured inside the p5js library when parent was called (on line 3 in sketch.js [/sketch.js:3:10])

If not stated otherwise, it might be an issue with the arguments passed to parent. (http://p5js.org/reference/#/p5/parent) 

While not very specific, it still did point out possible issue with arguments passed to parent

limzykenneth avatar Apr 01 '22 12:04 limzykenneth

That didn't happen to me

Falling10fruit avatar Apr 03 '22 09:04 Falling10fruit

Are you using p5.js (instead of p5.min.js) as FES is not included in the minified version.

limzykenneth avatar Apr 03 '22 13:04 limzykenneth

Doesn't understand Um, yes I'm using p5.js through the script tag in VSCode

Falling10fruit avatar Apr 04 '22 03:04 Falling10fruit

@Falling10fruit what @limzykenneth meant was if you were using the minified version of p5.js, because FES is not included in the minified version

check if your version is the minified one by looking if the js file that you include to include p5js ends with .min.js or just with .js if you still cant figure that out, then please send us the src="" attribute of the script tag that includes p5

justlucdewit avatar Apr 05 '22 14:04 justlucdewit

Oh, I'm using p5.js, not p5.min.js

Falling10fruit avatar Apr 06 '22 06:04 Falling10fruit

@Falling10fruit Can you share a simplified version of your project with us (HTML and JS)?

limzykenneth avatar Apr 06 '22 12:04 limzykenneth

`

p5.js example
`

`function setup() { // put setup code here var Canvas = createCanvas(0,0); Canvas.parent("Non-existent_Tag"); }

function draw() { // put drawing code here }`

Falling10fruit avatar Apr 06 '22 14:04 Falling10fruit

To simplify my mistake up there, all I did was add var Canvas = createCanvas(0,0,); & Canvas.parent("Non-existent_Tag"); in the empty example.

Falling10fruit avatar Apr 07 '22 01:04 Falling10fruit

Using the following sketch and p5.js 1.4.1 I'm still not able to replicate the issue

function setup(){
  var Canvas = createCanvas(0, 0);
  Canvas.parent("Non-existent_Tag");
}

FES message in console:

🌸 p5.js says: [main.js, line 3] An error with message "p is null" occurred inside the p5js library when parent was called. If not stated otherwise, it might be an issue with the arguments passed to parent. (http://p5js.org/reference/#/p5/parent)

Can you try replacing the p5.js script tag src URL value to https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.js?

limzykenneth avatar Apr 08 '22 14:04 limzykenneth

image

No difference

Falling10fruit avatar Apr 09 '22 09:04 Falling10fruit

Have you tried replacing the script tag URL as mentioned?

limzykenneth avatar Apr 09 '22 13:04 limzykenneth

Yes I did that image

Falling10fruit avatar Apr 10 '22 06:04 Falling10fruit

But the error in the debug console doesn't show that the error comes from the CDN version but from a local file instead.

limzykenneth avatar Apr 10 '22 23:04 limzykenneth

So how do I do that?

Falling10fruit avatar Apr 11 '22 01:04 Falling10fruit

I'm not entirely sure how you are currently running the html file as I'm expecting console messages from the browser console but you are showing the debug console in VSCode (I don't use it much) so I can't advise much from the provided info. You may want to move your question to the forum as it pertains more to your own code and I can't replicate the mentioned issue. Thanks.

limzykenneth avatar Apr 14 '22 19:04 limzykenneth

The debug console in VS Code is pretty much the same with the browser console. But instead it also gathers data from other tabs in the same window. Note that it creates a new window so it doesn't interfere with other tabs that I'm currently using.

Here's what the error looks like in the browser: image

Falling10fruit avatar Apr 15 '22 04:04 Falling10fruit

Also, I don't have an account for the forums.

Falling10fruit avatar Apr 26 '22 05:04 Falling10fruit

Hi @Falling10fruit, @limzykenneth : I tried replicating this issue. So the problem is something as follows: FES messages are being displayed in some browsers like Firefox(as expected) Screenshot 2023-06-18 at 11 28 48 AM and are not being displayed in some versions of Chrome. I also had a discussion with @nbriz @almchung regarding a similar issue that I was facing.

Ayush23Dash avatar Jun 18 '23 06:06 Ayush23Dash

@Ayush23Dash I'm still not sure what the issue is, can you share the replication steps?

limzykenneth avatar Jun 29 '23 13:06 limzykenneth

Seeing how there is so much difficulty in replicating this bug, I think my laptop is broken.

On Thu, Jun 29, 2023, 20:19 Kenneth Lim @.***> wrote:

@Ayush23Dash https://github.com/Ayush23Dash I'm still not sure what the issue is, can you share the replication steps?

— Reply to this email directly, view it on GitHub https://github.com/processing/p5.js/issues/5650#issuecomment-1613171575, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUI34SYUY4X3PYXFO3KW4SLXNV6GVANCNFSM5R64IPFQ . You are receiving this because you were mentioned.Message ID: @.***>

Falling10fruit avatar Jun 29 '23 23:06 Falling10fruit