-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
Log additional error properties #815
base: master
Are you sure you want to change the base?
Log additional error properties #815
Conversation
Signed-off-by: Felix Becker <[email protected]>
cf0cb17
to
e1adacf
Compare
removing stack logging can be troublesome, although with promises it anyways has become troublesome since promises just swallow all the information. I can't possibly merge this, as you're breaking the functionality by removing the explicit logging of the stack. Maybe you can adjust it so the stack logging still happens, or at least can be configured. |
I'm not sure I understand – isn't the stack still logged in the screenshot above? The information logged now is a strict superset of what was logged before |
The stack does not get logged by default on all error objects. That is why. |
Are you sure? What's an example of an error object that wouldn't have the stack logged by |
For reference, here's the code branch in NodeJS that formats errors:
If for some reason a non-Error instance was to be thrown with a Note also that the current code already doesn't support this case well, for example if somebody was to But if you'd like I could add an extra |
I second what @felixfbecker said, if the stack isn't being logged that's most likely an issue with the underlying logging framework, explicitly logging the error but not the stack is definitely not the norm and it removes a lot of useful information. |
Currently, when using SQL mode and a migration contains a syntax error,
db-migrate
will only print the error message and call stack:Even for a medium sized migration SQL file,
syntax error at or near ")"
can be like finding a needle in a haystack.When using
pg
, the Error actually contains additional information with the exact position of the syntax error. But currently, that information is not logged, as explicitly only thestack
of the error is logged.This PR changes it so that the entire error object is logged. Node's behavior when an
Error
is passed toconsole.error()
(which is used under the hood bylog.js
) is to log only thestack
property if there are no additional properties, meaning there would be no difference in those cases.But if there are additional properties, Node will log both the
stack
with message, and any properties after it:In particular, the
position
here can be copy-pasted into an editor's "go to position" command to jump exactly to the syntax error in the SQL file.Other properties can be helpful in case e.g. a DB constraints gets violated by the migration, as it can contain the constraint name, offending column values, etc.
One small change is also necessary to make sure the error gets properly logged: Throw the actual error if it's an
Error
instance instead of wrapping it in anAssertionError
, as the AssertionError just adds additional noise to the log and since the Error gets nested under theactual
property, it doesn't get expanded in the log but reduced to only[DatabaseError]
.There may be a small benefit in wrapping in an error given the error may not be an
Error
instance, but if it is, it makes more sense to throw the error directly.