question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fix: Exception / error handling directly accessing .stack and .message

See original GitHub issue

Describe the bug

In multiple places in the code within a catch block the .message and .stack is directly getting accessed without any checks. As possibly all things can be thrown in TypeScript / JavaScript (even undefined or null etc.) and not only Error objects. Therefore it needs to be validated first if .message respective .stack are existing before they are getting accessed. Furthermore a fallback should be implemented in case the thrown objects are no regular Error objects and not providing the requested properties or the stringify of the .stack for example is failing due to hierarchy depth etc.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
petermetzcommented, Jan 10, 2022

Do you happen to have any code examples that validate the .message and .stack before they are getting accessed?

@Leeyoungone Yup, this is it:

if (ex instanceof Error) {
// ex has .message and .stack
}
1reaction
m-courtincommented, Dec 30, 2021

@petermetz: Thank you very much for the heads-up about the PR @Leeyoungone is working on. So I will only include the basic functionality into my PR that @Leeyoungone can use it in her PR

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Handling - OWASP Cheat Sheet Series
We indicate to the handler, via the annotation @ExceptionHandler, to act when any exception extending the class java.lang.Exception is thrown by the application ......
Read more >
Error Handling Flaws - Information and How to Fix - Veracode
In many cases, improper error handling is a result of using default error handlers. These messages may include detailed information about a file...
Read more >
Thoughtful Error Handling - Medium
Consider standardizing your error messages with an error code. Ensure error messages provide enough information to resolve security incidents ...
Read more >
Best Practices for exceptions - .NET - Microsoft Learn
Use exception handling if the event doesn't occur often, that is, if the event is truly exceptional and indicates an error, such as...
Read more >
9 Best Practices to Handle Java Exceptions - Stackify
Exception handling is an error-handling mechanism. When something goes wrong, an exception is thrown. If you do nothing, the exception causes ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found