Skip to content

Errors without stack trace not supported #78

@AylenHoz

Description

@AylenHoz

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:

WhatsApp Image 2025-05-28 at 09 38 25

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions