Improve FES error messages for color functions in p5.strands
Increasing access
Clear error messages help beginners debug shader code. The current FES messages for color functions in strands don't mention the specific function name or the invalid value, making it hard to know what went wrong. The newly added color APIs in p5.strands expose a few cases where Friendly Error System (FES) messages could be more specific and beginner-friendly.
Most appropriate sub-area of p5.js?
- [ ] Accessibility
- [x] Color
- [ ] Core/Environment/Rendering
- [ ] Data
- [ ] DOM
- [ ] Events
- [ ] Image
- [ ] IO
- [ ] Math
- [ ] Typography
- [ ] Utilities
- [ ] WebGL
- [ ] Build process
- [ ] Unit testing
- [ ] Internationalization
- [x] Friendly errors
- [ ] Other (specify if possible)
Feature enhancement details
Three FES message improvements for strands color functions:
-
Missing parameter —
lerpColor(c, 0.5)(missing second color arg): Current:"Function 'mix' has 3 variants which expect 3 arguments, but 2 were provided."Suggested: mentionlerpColorby name, not the internalmixfunction -
Wrong parameter type —
red("blue")orlerpColor(c1, "blue", 0.5): Current:"You've tried to construct a scalar or vector type with a non-numeric value: blue"Suggested: also name which function was called and which argument was bad -
Invalid color string —
color('#fv0a'): Current:"Error: Invalid color string"Suggested: include the invalid string in the message so users know what to fix
Related PR: #8822
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms.
For guidance on contributing, check out our contributing guidelines and other resources for contributors. 💬 If you have questions or need support, feel free to join the Processing Foundation Forum or visit our Community page. 📜 Please also review our Code of Conduct to understand our community standards. Thank You!
Hi! I'd like to work on this issue.
I traced all three messages to their source:
-
lerpColornamingmix-lerpColor()insrc/strands/strands_api.jsforwards its arguments straight tothis.mix(...args), so when the argument count is wrong, the arity check infunctionCallNode(src/strands/ir_builders.js) reports the internalmixfunction, notlerpColor. -
Generic "non-numeric value" message -
red(),green(),blue(),alpha(),hue(),saturation(),brightness(), andlightness()all route throughp5.strandsNode()→primitiveConstructorNode→mapPrimitiveDepsToIDsinir_builders.js. That function has no context about which user-facing function or argument position triggered the error, so it can only report the raw bad value. -
"Invalid color string" with no string - thrown in
src/color/p5.Color.js. The offending value (vals[0]) is right there in scope when the error is thrown, it's just not included in the message.
My plan:
- Add an explicit arg-count check inside
lerpColor()before it delegates tomix(), so mismatched calls reportlerpColorby name (e.g. "lerpColor() expects 3 arguments (color1, color2, amount), but 2 were provided."). - Thread an optional
contextobject ({ functionName, argIndex }) throughmapPrimitiveDepsToIDs→primitiveConstructorNode→p5.strandsNode, and pass it from the color accessor functions so type errors can name both the function and the argument that caused it. - Update the
p5.Color.jscatch block to include the actual invalid string in the thrown error. - Add unit tests covering all three cases (missing arg, wrong type, invalid color string) so regressions are caught going forward.
Could I get this assigned to me? Happy to open a draft PR early for feedback if that's preferred over waiting.
Hi @Manju! This looks like a well-researched plan - you've correctly identified all three root causes. Feel free to go ahead and work on this. A draft PR early for feedback sounds like a good approach. You may also want to loop in @davepagurek as he's the primary reviewer for strands-related changes.