-
-
Notifications
You must be signed in to change notification settings - Fork 603
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 error stack traces to the console #1940
Log error stack traces to the console #1940
Conversation
The second argument was being lost
val = val.stack; | ||
} | ||
|
||
console.error(`[webpack-cli] ${red(val)}`); |
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.
Why? error.toString() always show the stacktrace
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.
In Node 14 error.toString()
only shows the error message.
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.
Ditto in Node 12.x and 13.x as well.
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.
@@ -55,7 +55,8 @@ const addonGenerator = ( | |||
try { | |||
mkdirp.sync(pathToProjectDir); | |||
} catch (err) { | |||
logger.error('Failed to create directory', err); | |||
logger.error('Failed to create directory'); |
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.
logger.error(Failed to create directory: ${err}
);
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.
See comment above about error.toString()
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.
No:
error.js
const error = new Error('test');
console.log(error);
and run node: error.js
Error: test
at Object.<anonymous> (/home/path/to/test.js:1:77)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
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.
This is special handling by the console functions.
The code doesn't do that because logger.error
does this:
console.log(`[webpack-cli] ${error}`)
Which at runtime is the same as:
console.log('[webpack-cli] ' + error.toString())
Which does not print the stack trace. Did you check out the test repo which showcases the behavior?
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.
A more direct test would be to log the error using the logger. You can create a test.js
file in the root of the repo with this code:
const logger = require("webpack-cli/lib/utils/logger");
logger.error(new Error("test"));
And see it not have the expected behavior when you run it with node test.js
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.
Need improve
What kind of change does this PR introduce?
Show stack traces for errors logged by webpack-cli.
Did you add tests for your changes?
No.
If relevant, did you update the documentation?
No.
Summary
An error occurring in a plugin (for example calling missing APIs or just throwing an error during
apply()
) results in a displayed error but no stack trace. This in turn makes it nearly impossible to track down the source of the problem and address it.You may see an example of what I'm trying to address here: https://github.com/thecrypticace/webpack-cli-stack-traces
Does this PR introduce a breaking change?
No.
Other information
n/a