Skip to content

Conversation

@Mario5T
Copy link

@Mario5T Mario5T commented Nov 10, 2025

The Problem (Issue #8212)

When using functions like createVector(10, NaN) or float() incorrectly, the Friendly Error message would point to the line in the p5.js library file that executes the error message, rather than the line in the user's sketch that caused the error.
This made debugging difficult for users.


Root Cause

In validate_params.js, the code used a hardcoded stack frame index parsed[3] to extract the location of the error.
This assumed a fixed call stack depth, which didn't account for errors originating from within p5.js library functions.


Typical Stack Trace

Index Description
[0] Error creation in _friendlyParamError
[1] _friendlyParamError itself
[2] _validateParameters
[3] The p5.js function (e.g., createVector, float) ← was pointing here
[4] User's code ← should point here

The Fix

Modified validate_params.js (lines 608–672) to:

  • Detect the p5.js library file name by throwing a test error and parsing its stack trace
  • Filter out all frames from the p5.js library to find the first frame from user code
  • Use the user's code frame for error location reporting
  • Maintain backward compatibility by falling back to parsed[3] if no user frame is found

This approach mirrors the logic already used in the processStack() function in fes_core.js for handling global errors.


Testing

The fix can be tested with the examples from the bug report:

function setup() {
  let vectorA = createVector(10, NaN);  // Error will now point to this line
  let vectorB = createVector(vectorA.x + vectorA.y, vectorA.y);
}

…ces were pointing to the p5.js library code instead of the user's code.
@welcome
Copy link

welcome bot commented Nov 10, 2025

🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors!
🤔 Please ensure that your PR links to an issue, which has been approved for work by a maintainer; otherwise, there might already be someone working on it, or still ongoing discussion about implementation. You are welcome to join the discussion in an Issue if you're not sure!
🌸 Once your PR is merged, be sure to add yourself to the list of contributors on the readme page !

Thank You!

@Mario5T
Copy link
Author

Mario5T commented Nov 12, 2025

@perminder-17 plz review it.

@perminder-17
Copy link
Collaborator

Hi, thanks for your work and your patience. #8212 (comment) I just wrote a comment, and could wait for the approvals?

@Mario5T
Copy link
Author

Mario5T commented Nov 12, 2025

@perminder-17 just asking if the issue is approved to be worked on will my pr be considered?

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 this pull request may close these issues.

2 participants