-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Users are unable to differentiate between missing plugins and plugins that throw exceptions as they are loaded #7668
Comments
I think outputting a "plugin not found" error if a plugin throws an error while loading is a bug; it's giving the user incorrect information and making errors more difficult to identify. The current behavior is for the engine to catch all errors, even though the engine can only handle a module-not-found error. If plugin throws an error, it should be treated the same as an unexpected error within ESLint, and should crash the process with a stack trace. We can distinguish module-loading errors from other errors with something like: try {
plugin = require(pluginFile);
} catch (err) {
if (err.code === "MODULE_NOT_FOUND") {
// output "missing plugin" message
} else {
// crash the process and output a stack trace
}
} |
Instead of checking
Note that an error with code |
@Slayer95 Does |
I don't think |
It does, however, cache the resolution of real paths, which is (one of) the most expensive operations when locating modules. ... I suppose there is still a trade-off between correctness and performance, though. |
We could do the try {
plugin = require(pluginFile);
// loaded plugin successfully, continue with linting process
} catch (err) {
try {
require.resolve(pluginFile);
// plugin threw an error, crash with stack trace
} catch (err2) {
// Missing plugin
}
} That would avoid hurting performance on the hot path, and only do extra work when something is wrong. |
I imagine it would be easy to set up a benchmark which checks this. Sorry for dragging us into the weeds. @eslint/eslint-team Anyone else have any thoughts on this issue? |
I agree with this. What @not-an-aardvark suggested seems like a good strategy to me. |
@platinumazure This issue seems very similar to #6874, which is already accepted. Can this all be handled together? |
@kaicataldo I suppose so. I'll close this. |
Tell us about your environment
N/A (applies to all environments)
What parser (default, Babel-ESLint, etc.) are you using?
N/A
Please show your full configuration:
Any configuration which specifies a plugin which throws when trying to require the plugin module.
What did you do? Please include the actual source code causing the issue.
Run ESLint on files or text.
What did you expect to happen?
Error message says that the plugin was found but could not be loaded, plus possibly debugging information.
What actually happened? Please include the actual, raw output from ESLint.
The "messages/plugin-missing.txt" is rendered, same as if the plugin was missing.
How should we solve this? Here are the high-level options as I see them:
The text was updated successfully, but these errors were encountered: