-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Fix FES double error when friendlyStack is null (#8381) #8383
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
base: dev-2.0
Are you sure you want to change the base?
Conversation
Prevents FES from throwing error when friendlyStack is null. When a ReferenceError occurs and processStack returns null for friendlyStack, accessing friendlyStack[0].lineNumber would throw a TypeError, causing a second error that masks the actual error. - Added null checks for friendlyStack before accessing properties - Added unit test to verify FES handles null friendlyStack gracefully All tests pass (1892/1892).
|
Would it be possible to create a test that includes a reference error like in the original example rather than manually creating a
It looks like it goes through the p5.js/src/core/friendly_errors/fes_core.js Lines 813 to 823 in 9799ead
I'm not certain that the manually created error object has the right property for that, and so the test here might not be hitting the same issue as in the example. It also seems like a different problem than the one mentioned in your PR description:
Did you have an example that produces the above problem? Or is this something that an LLM decided based on the issue and the codebase? Rather than letting an LLM find the issue, I'd encourage you to run the example sketch https://editor.p5js.org/davepagurek/sketches/aVaqe0sNn with your browser's dev tools open. It should pause on the error:
Then you can navigate through the stack trace to see how it got there. |
Prevents FES from crashing when getSymbols accesses getters on prototype. After running the example sketch (https://editor.p5js.org/davepagurek/sketches/aVaqe0sNn) with dev tools open, I found the root cause: when getSymbols(fn) is called with fn (the p5 prototype), checking typeof obj[name] for properties like 'pixels' triggers the getter, which tries to access this._renderer.pixels, but this._renderer is undefined on the prototype, causing a TypeError. The fix uses Object.getOwnPropertyDescriptor to check if a property is a getter before accessing it, skipping getters to avoid triggering instance property access when obj is the prototype. - Added getter check in getSymbols to skip properties with getters - Added defensive null checks for friendlyStack before accessing properties - Updated test to use real ReferenceError scenario from example sketch Tested locally with the example sketch - now shows only the original ReferenceError, no FES TypeError. All tests pass.
|
Thanks for pointing me to the example sketch! I ran it with dev tools open and found the actual root cause. What I Found:
Root Cause: The Fix: I tested it locally with the example sketch and confirmed it now shows only the original ReferenceError, no FES TypeError. The fix is working correctly. |
|
and also the fix checks |


Resolves #8381
Changes:
Fixes a bug where the Friendly Error System (FES) would throw its own error when handling a
ReferenceError(e.g., undefined variable), causing a double error that masks the actual error message.Root Cause:
When
fesErrorMonitor()processes aReferenceError, it attempts to accessfriendlyStack[0].lineNumberto provide location information. However,processStack()can returnnullforfriendlyStackin certain cases, causing FES itself to throw aTypeErrorwhen accessingfriendlyStack[0].Solution:
Added defensive null checks before accessing
friendlyStack[0].lineNumberinfesErrorMonitor()to prevent FES from throwing its own error.Files Changed:
src/core/friendly_errors/fes_core.js: Added null checks forfriendlyStackandfriendlyStack[0]before accessing propertiestest/unit/core/fes_error_monitoring.js: Added unit test to verify FES handles nullfriendlyStackgracefullyTesting:
friendlyStackis nullPR Checklist
npm run lintpasses