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

How do I use this to log an error that I have already caught? #36

Closed
papb opened this issue Sep 28, 2020 · 2 comments
Closed

How do I use this to log an error that I have already caught? #36

papb opened this issue Sep 28, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@papb
Copy link

papb commented Sep 28, 2020

I have an error variable that I caught from somewhere else. I would like to log it cleanly to console just like this library does. However, from the readme, it looks like this library only acts on uncaught errors. Does this library also provide a way to do this?

@ehmicky ehmicky added the enhancement New feature or request label Sep 28, 2020
@ehmicky
Copy link
Owner

ehmicky commented Sep 28, 2020

Hi @papb 👋

At the moment, the logic related to error formatting is not decoupled from the logic related to error handling, so you would need to handle the errors using log-process-errors to benefit from the error formatting.

One thing to keep in mind is that the error formatting needs not only the error instance, but also any properties passed to the process event. For example, in process.on('unhandledPromise', (error, promise) => {...}, both error and promise are printed by the error formatter (since they are both interesting). So if we were to decouple error formatting, users would need to pass those arguments along as well. Although we could make those additional arguments optional (but the output will be less informative).

Decoupling the formatting logic is not completely straightforward though, so I'd like to ask you: would the log option be a solution for you? This would require you to catch the error using log-process-errors, but you would still be able to run your custom logic.

@papb
Copy link
Author

papb commented Oct 16, 2020

Hello, thank you for the fast reply. No, the log option wouldn't work for me; I have already caught the error within a try-catch block.

However, I decided I don't really need this for now, so don't worry about it :)

@papb papb closed this as completed Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants