Skip to content
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

[BUG] Info from Hooks.onError getting lost #76

Closed
Ethaks opened this issue Jan 28, 2023 · 3 comments
Closed

[BUG] Info from Hooks.onError getting lost #76

Ethaks opened this issue Jan 28, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Ethaks
Copy link

Ethaks commented Jan 28, 2023

Describe the bug
Having libWrapper active changes contents of errors logged via Hooks.onError, leading to error information being removed.

To Reproduce
Run the following snippet in a console:

try {
  const foo = null;
  foo.bar = false;
} catch (e) {
  Hooks.onError("Test function", e, {
    msg: "Something's wrong",
    log: "error",
  });
}

Expected behavior
The expected error message by default Foundry looks like this (i.e. includes the msg given to Hooks.onError):
default

Screenshots
The error with libWrapper active looks like this:
libWrapper

Technical Details (please complete the following information):

  • LibWrapper Version 1.12.11.0
  • FoundryVTT Version 10.291
  • Browser & Version Chrome 108
@Ethaks Ethaks added the bug Something isn't working label Jan 28, 2023
@ruipin
Copy link
Owner

ruipin commented Jan 28, 2023

LibWrapper wraps Hooks.onError to add the list of affected packages to the error. This is probably a bug with that piece of code. I'll take a look once I'm back home on Monday.

Thanks for the report, I was unaware of this difference in behaviour!

@ruipin ruipin self-assigned this Jan 28, 2023
@ruipin
Copy link
Owner

ruipin commented Jan 30, 2023

This seems to occur in Chrome anytime something causes the error to generate the corresponding stack message (in the stack property). Once that happens, the stack trace (which is what is displayed to the user) permanently copies the current error message, so any future modifications of the message will not be reflected in the stack trace.

Chrome delays generating the stack trace until someone reads it. LibWrapper reads this property to parse the package list, causing the stack to be generated before the Something's wrong message is prepended to the error message.

You can reproduce this without libWrapper by setting a breakpoint in the onError function, before msg is prepended to error.message. In such a case, the browser debugger causes error.stack to be generated with the improper message.

Firefox instead implements error.stack as an accessor that dynamically prepends the error message to the generated stack whenever accessed, meaning that this issue does not exist there. It affects solely Chrome (and Chromium).

I'll see if I can implement a workaround to avoid libWrapper causing it, but technically it is not a libWrapper bug, just a limitation of how Javascript exception messages are handled by Chrome.

@ruipin
Copy link
Owner

ruipin commented Jan 30, 2023

Workaround added in v1.12.12.0.

The message now shows correctly on both Chrome/Chromium and Firefox.

Closing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants