Skip to content

Support errors without stack trace #87

Open
aguscoe wants to merge 2 commits intopoppinss:4.xfrom
aguscoe:feature/optional-chaining
Open

Support errors without stack trace #87
aguscoe wants to merge 2 commits intopoppinss:4.xfrom
aguscoe:feature/optional-chaining

Conversation

@aguscoe
Copy link

@aguscoe aguscoe commented Mar 16, 2026

🔗 Linked issue

#78

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Some errors may not include a stack trace, depending on whether the error provides valuable information when thrown. This is why the stack property on JavaScript's Error class is optional. When using Youch to parse an error without a stack trace, an error is thrown because this case is not supported:

image

Fix: Add optional chaining (?.) in the stack trace script so that addEventListener is not called when the target element does not exist.

📝 Checklist

  • I have read the contribution guide.
  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@aguscoe aguscoe marked this pull request as ready for review March 16, 2026 16:27
@thetutlage
Copy link
Member

Can you please share a reproduction of this error, before we can go ahead with a fix?

@aguscoe
Copy link
Author

aguscoe commented Mar 19, 2026

Can you please share a reproduction of this error, before we can go ahead with a fix?

Yes, sure. To replicate it, all you have to do is something like this:

const err = new Error('My custom error'); 

delete.err.stack

throw err

And you'll see the error I included in the description. It's the same error reported here. I understand this has already been discussed, but the error remains.

@thetutlage
Copy link
Member

@aguscoe

If you run the examples/web.ts file and then visit /no-trace, you will see an example without stack trace working fine with no console.log errors.

CleanShot 2026-03-20 at 10 14 58@2x

As said earlier, it will be nice to share a proper reproduction. A code example, that I can run right away, see the issue and then dig further

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