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

[p5.js 2.0 Bug Report]: Warnings about omitting strokes on high-detail 3D primitives don't use FES

Open davepagurek opened this issue 10 months ago • 19 comments

Most appropriate sub-area of p5.js?

  • [ ] Accessibility
  • [ ] Color
  • [ ] Core/Environment/Rendering
  • [ ] Data
  • [ ] DOM
  • [ ] Events
  • [ ] Image
  • [ ] IO
  • [ ] Math
  • [ ] Typography
  • [ ] Utilities
  • [x] WebGL
  • [ ] Build process
  • [ ] Unit testing
  • [ ] Internationalization
  • [ ] Friendly errors
  • [ ] Other (specify if possible)

p5.js version

All

Web browser and version

All

Operating system

All

Steps to reproduce this

Steps:

  1. Turn off FES
  2. Draw a cylinder with a high level of detail
  3. It still logs a warning

That's because these sorts of warnings are raw console.logs in the codebase: https://github.com/processing/p5.js/blob/9799eada451dea7f2b50fe5f52ffd725463b343a/src/webgl/3d_primitives.js#L2582-L2585

Snippet:

p5.disableFriendlyErrors = true
function setup() {
  createCanvas(400, 400, WEBGL);
  cylinder(20, 100, 40, 40)
}

Additionally, this also triggers when you are drawing to a p5.Geometry, i.e.:

function setup() {
  createCanvas(400, 400, WEBGL);
  const myGeom = buildGeometry(() => cylinder(20, 100, 40, 40))
  noStroke()
  model(geom)
}

Arguably we should just silence this error if inside of buildGeometry since we don't know if it will eventually be drawn with strokes or not, to avoid misleading false positives.

davepagurek avatar Jan 07 '26 18:01 davepagurek

I’d like to work on this. The warning appears to bypass FES due to a raw console.log. I’ll investigate fixing or silencing it appropriately

Aayushdev18 avatar Jan 07 '26 19:01 Aayushdev18

This does look like a clear FES consistency issue.

From reading the code, it seems the warning for high-detail cylinders is currently emitted via a raw console.log, so it still appears even when p5.disableFriendlyErrors = true. This also seems to trigger inside buildGeometry(), where stroke usage isn’t yet known, which could lead to misleading warnings.

I’d be interested in helping fix this and align the behaviour with the Friendly Error System if that sounds reasonable. Thank you 😇

shuklaaryan367-byte avatar Jan 08 '26 12:01 shuklaaryan367-byte

i agree this can be misleading for beginners. i’m happy to take this if no one’s on it?

skyyash avatar Jan 09 '26 13:01 skyyash

From reading the issue, it looks like the warning is meant to discourage strokes on very high-detail primitives for performance reasons, but the current message doesn’t use FES and can be confusing for users. I wanted to confirm whether the main goal here is improving the warning’s delivery (via FES) or refining when it should trigger.

RitwikaParua avatar Jan 11 '26 11:01 RitwikaParua

Observation: When FES is disabled, drawing a cylinder with high detail values still logs a warning. This appears to be because the message is emitted via a raw console.log/console.warn rather than going through the Friendly Error System. As a result, the warning bypasses FES entirely and is shown regardless of whether FES is enabled.

Expected behavior: User-facing warnings like this should respect the FES setting and not appear when FES is turned off.

Suggestion: Routing this warning through FES (or conditionally suppressing it when FES is disabled) would align it with other p5.js error messaging behavior.

RitwikaParua avatar Jan 11 '26 12:01 RitwikaParua

Hey @davepagurek, I am new to the p5.js community and I would love to contribute to this issue. Kindly assign it to me, looking forward towards your reply.

Vedant1816 avatar Jan 12 '26 09:01 Vedant1816

Hi everyone! I'm going to assign this one to @skyash-dev. In general we prefer people finish their ongoing PRs in the p5 repo before taking on new ones, and also we generally discourage comments that just add to the noise by restating what's already in the issue (if AI is writing comments, as a reminder, we discourage that too -- feel free to use AIs to help you understand an issue, but do try to communicate on a human level.)

davepagurek avatar Jan 12 '26 13:01 davepagurek

@davepagurek just to confirm, the warning should not appear when geometry created via buildGeometry() is later drawn with model(), right?

skyyash avatar Jan 12 '26 15:01 skyyash

I think that's probably easiest for now, since I suspect to do that would involve storing a warning somewhere on a property of the geometry for us to later check and log, and that feels like maybe not the right use of the p5.Geometry class for now. I'm open to other ideas though! But we can always do that later.

davepagurek avatar Jan 12 '26 15:01 davepagurek

@davepagurek not overloading geometry makes sense, i’ll go with suppressing the warning during buildGeometry() for now.

i also noticed a few other places using raw console.log for warnings. is there a reason those aren’t routed through FES yet?

skyyash avatar Jan 13 '26 13:01 skyyash

Probably those should all go through FES. Although, FES normally reports errors, and it's probably important to make sure this is treated as just a warning. FES's error logging function lets you supply a CSS color to it, but it sounds like maybe we want to create a more general warning logging function that we can use everywhere so we get consistent formatting across all warnings?

Your last PR is for main, for 1.x, where we're just doing bug fixes at the moment. Potentially what you've got there is sufficient for 1.x, since adding a new logging method sounds like maybe a bigger update than we want for that version. Do you think it makes sense to call that one done, and make a similar change to dev-2.0 for the 2.x releases, but also tackling the console.logs there?

davepagurek avatar Jan 21 '26 23:01 davepagurek

@davepagurek i think the main PR is fine as-is for now, since there isn’t a warning API yet.

for 2.x though, i like the idea of having a proper warning helper. i can look into making a similar change in dev-2.0 and see what a reasonable approach might be. in the meantime, could you share some references on FES that i could read? that’d help in thinking about a warning helper. if i’m understanding right, you’re suggesting something like p5._friendlyError(), but for warnings, e.g. p5._friendlyWarning(). what solution you have in mind?

skyyash avatar Jan 23 '26 09:01 skyyash

Ok sounds good, I'll merge that one in then!

Yeah the main function is _friendlyError which calls _report, which is possibly flexible enough in formatting for us to use for warnings too when given the right color parameters.

davepagurek avatar Jan 23 '26 19:01 davepagurek

@davepagurek would you prefer that i open an issue first to propose a warning helper for 2.0, or go ahead with a PR implementing something minimal like:

p5._friendlyWarning = function(message, func) {
  if (p5.disableFriendlyErrors) return;
  p5._report(message, func, '#C77D00'); // warning color?
};

we could keep it simpler and just pass a distinct color (e.g. #C77D00).

is it something you are suggesting or something more structured at the _report level?

skyyash avatar Feb 14 '26 07:02 skyyash

should we open a new issue for handling warnings?

skyyash avatar May 09 '26 08:05 skyyash

Hi @skyash-dev! I think it's ok to make that as a PR for this issue.

davepagurek avatar May 10 '26 11:05 davepagurek

hey @davepagurek! i think we might not need a new warning helper. FES.warn already exists in fes.js at 126, it maps to console.warn and respects disableFriendlyErrors, same as FES.log / FES.error do. were you thinking of something the FES methods don't cover?

should we replace raw logs with it?

skyyash avatar Sep 10 '26 06:09 skyyash

Using FES.warn sounds ok to me! Thanks

ksen0 avatar Sep 10 '26 11:09 ksen0

hi @davepagurek is anyone wokring on this issue , I would like to take this up , I suggest replacing the console.log() warnings in src/webgl/3d_primitives.js with FES.warn() so they respect the Friendly Error System settings.

I am still looking upon the other issue regarding buildGeometry() case, where the warning may appear even if the resulting geometry is later rendered without a stroke.

I would like to get your say on the fix I am proposing

yogesh7547 avatar Oct 14 '26 09:10 yogesh7547