Package version
4.1.0-beta.11
Describe the bug
There are errors that could not have a stack trace, depending on whether the error would provide valuable information or not when throwing the error. This is why the Error class in JavaScript has an optional stack property.
When trying to use Youch to parse an error without a stack, the following error is displayed in the browser’s console:

This error occurs only when the error has no stack, and therefore, the HTML elements that Youch adds to the final result using the stack trace script are not present. This results in addEventListener being called on non-existent HTML elements (for example, here).
Using Error doesn't guarantee that the error always has a stack, as it's an optional property in JavaScript (the JavaScript specification doesn't require its presence).
If we respect the Error type, the stack should be optional.
Solution
The addEventListener for HTML elements added using the stack trace script should be defined with an optional chain, so that if the querySelector doesn't find the element, it won't execute addEventListener.
This PR has these changes: #77
Reproduction repo
No response
Package version
4.1.0-beta.11
Describe the bug
There are errors that could not have a stack trace, depending on whether the error would provide valuable information or not when throwing the error. This is why the
Errorclass in JavaScript has an optional stack property.When trying to use Youch to parse an error without a stack, the following error is displayed in the browser’s console:
This error occurs only when the error has no stack, and therefore, the HTML elements that Youch adds to the final result using the stack trace script are not present. This results in
addEventListenerbeing called on non-existent HTML elements (for example, here).Using
Errordoesn't guarantee that the error always has astack, as it's an optional property in JavaScript (the JavaScript specification doesn't require its presence).If we respect the
Errortype, thestackshould be optional.Solution
The
addEventListenerfor HTML elements added using the stack trace script should be defined with an optional chain, so that if thequerySelectordoesn't find the element, it won't executeaddEventListener.This PR has these changes: #77
Reproduction repo
No response