RFC: Error and Reporting Alignment
See original GitHub issueProposal for Codifying Errors Across the Ecosystem for Consistent Reporting
While working on webpack-stylish
one thing has become glaringly obvious: the format of errors in and out of webpack proper, across the ecosystem and between loaders and plugins, is extremely inconsistent. This ultimately provides a poor user experience when debugging errors. And would open greater opportunities to mitigate new-user intimidation by the output. (ref: https://twitter.com/marvinhagemeist/status/965134200012713984)
Examples
A warning sample from webpack:
‘./entry.js\n6:12-19 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted\n @ ./entry.js’
An error sample from webpack:
’./entry.js\nModule not found: Error: Can\’t resolve \‘test\’ in \‘/code/webpack-stylish/test/fixture\‘\n @ ./entry.js 6:14-29’
Errors from the performance
features: https://github.com/webpack/webpack/blob/master/lib/performance/AssetsOverSizeLimitWarning.js
An ecosystem example: https://github.com/JaKXz/stylelint-webpack-plugin/blob/master/lib/run-compilation.js#L38. Whereby this plugin is passing along stylelint-formatted errors in a group, as a single error, to the compilation.
All are of a different format, containing different formats of information without. The performance (and others) errors are vastly different as their messages contain lists of files replete with newlines. As you can see from the error and warning examples, the line:column positions are in different places.
Identifiable Problems
- Messages are overly verbose
- Lack of consistent toString()
- Line number and column representation is not consistent
- Metadata accessible only in the error message (eg. list of assets)
Proposed Solution
My proposal is multi-faceted:
- Create a standard
WebpackError
class containing the following signature:
abstract class WebpackError {
get id // hash identifying the error
get/set message
get/set name // name to identify the file, error category, group, etc. eg. "performance" or "configuration"
get/set lineNumber
get/set column
get/set columnEnd // some webpack errors contain a column range
get metaData // object provided to set error-specific data. eg. an asset list
function toString([formatterFn]) // formatterFn can/should be set in the constructor, if needed
}
The base class would be abstract
only in that the class should not be directly instantiated. The class should be extended/inherited by a subclass. This will provide for more accurate identification of Error sources, should the provided information in the class be insufficient.
toString()
will by default output in the following format:
{lineNumber}:{column} {name}: {message}
There may be an opportunity to automate rendering of metaData
as well.
-
Enforce by proxying as a warning in v3, and as an error in v4+, that all objects pushed to
compilation.errors
andcompilation.warnings
be an instance ofWebpackError
-
Error if
WebpackError
instance is created without minimum set of options: column, lineNumber, message, name. -
Warn if a
WebpackError
has a message set longer than a reasonable preset value. (ReferenceESLint
for example, which imposes reasonable error message lengths) -
Update both v3 and v4 to use these patterns.
-
Update loaders in webpack-contrib to use these patterns.
-
Write blog post outlining the changes needed by 3rd party loader/plugin authors.
-
Update webpack.js.org to include a page on error reporting.
Conclusion
I believe these changes will be a great improvement to webpack on the whole. As mentioned, it will greatly improve the user experience, aid in debugging, and reduce new user and adoption friction.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:9
- Comments:8 (8 by maintainers)
Yes, they should be serializable. I don’t foresee any issue with the proposal being so, but it’s possible that classes with extend that error class may implement code that is not. However, I’m not sure how we’d enforce that as yet.
This effort is being abandoned due to managerial disagreement. Copying from PR #6823: