-
Notifications
You must be signed in to change notification settings - Fork 7
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
Always show stack trace on errors #4
Conversation
Is there a reason not not display the stack trace on all cases for |
That could be noisy, as 'error' is a low level error, which would change
I considered the |
It would help a lot to be able to debug certain situations with the ability to turn on trace logging for errors. This problem - bcoin-org/bcoin#762 - is a good example because without the trace, its really hard to know what is wrong. If not using with an environment variable, maybe a new log level is defined that is |
The default behavior of |
There are also not that many places an error is logged in bcoin:
|
I think the best option is to include the stack for all errors for |
Agreed. Updated PR to always show stack if present. Also removed existing logic for showing stack in streams only, since this is now redundant. |
lib/logger.js
Outdated
@@ -514,12 +514,12 @@ class Logger { | |||
if (level !== Logger.levels.ERROR) | |||
msg = `Error: ${msg}`; | |||
|
|||
this.log(level, module, [msg]); | |||
// Always record stack traces for assertion failures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This comment is outdated.
Looks good, tested with bcoin and handling node errors. |
This does result in lots of this noise on my main-net fullnode:
This is one of the reasons I was checking by error code. Perhaps adding something to Thoughts @braydonf ? |
That is an info log not an error? I'll take a look at options. |
My guess is it's because VerifyError extends Error class, so probably hits this: I will have to test this more locally, I just noticed this on my production node. |
Okay, yeah. It would probably be better to either send the |
Another case that is expected, and may not need the stack (though is a debug log):
|
Yeah, the diff --git a/lib/net/pool.js b/lib/net/pool.js
index 82d31c9c..a5bc478a 100644
--- a/lib/net/pool.js
+++ b/lib/net/pool.js
@@ -2441,7 +2441,7 @@ class Pool extends EventEmitter {
} catch (err) {
if (err.type === 'VerifyError') {
peer.reject('tx', err);
- this.logger.info(err);
+ this.logger.info(err.message);
return;
}
throw err; |
Okay, all updates (including the above) are at bcoin-org/bcoin#771 |
Issue
Assertion errors are difficult to debug.
In bcoin it's common to see errors such as this in logs:
[error] (node) false == true
or[error] (node) Assertion failed.
Without a stack trace it is impossible to determine the cause of these errors.
We don't want a stack trace to show for every error thrown, but assertions
are an exception.
Solution
Using
ERR_ASSERTION
code to always show stack trace in this case.Was hoping for a more general solution than relying on error code,
but I've decided it makes sense to consider assertions a special
exception case that we should handle specifically.
Example result after change:
Caveat:
This does result in duplicate stack traces showing in stream due to this line:
blgr/lib/logger.js
Lines 524 to 527 in f4de8ba
I'm not sure what the best solution is yet, short of adding a
code !== 'ERR_ASSERTION'
check,but there could be some consequences here.
Related discussions:
bcoin-org/bcoin#762 (comment)
https://github.com/bcoin-org/bcoin/pull/605/files#r256155372