From 8f6c2e7ac69eaba1413cde9ff33da16f0b1c60ac Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Fri, 19 Feb 2016 11:32:01 -0800 Subject: [PATCH] Update: Better error message for plugins (refs #5221) --- bin/eslint.js | 21 ++++++++++++++++++++- lib/config/plugins.js | 4 ++++ messages/plugin-missing.txt | 9 +++++++++ package.json | 3 ++- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 messages/plugin-missing.txt diff --git a/bin/eslint.js b/bin/eslint.js index 598b568ba4e0..19e5720a711f 100755 --- a/bin/eslint.js +++ b/bin/eslint.js @@ -29,12 +29,31 @@ if (debug) { // now we can safely include the other modules that use debug var concat = require("concat-stream"), - cli = require("../lib/cli"); + cli = require("../lib/cli"), + path = require("path"), + fs = require("fs"); //------------------------------------------------------------------------------ // Execution //------------------------------------------------------------------------------ +process.on("uncaughtException", function(err){ + // lazy load + var lodash = require("lodash"); + + if (typeof err.messageTemplate === "string" && err.messageTemplate.length > 0) { + var template = lodash.template(fs.readFileSync(path.resolve(__dirname, "../messages/" + err.messageTemplate + ".txt"), "utf-8")); + + console.log("\nOops! Something went wrong! :("); + console.log("\n" + template(err.messageData || {})); + } else { + console.log(err.message); + console.log(err.stack); + } + + process.exit(1); +}); + if (useStdIn) { process.stdin.pipe(concat({ encoding: "string" }, function(text) { try { diff --git a/lib/config/plugins.js b/lib/config/plugins.js index 7281e48eabfc..d1bfbd83fa0c 100644 --- a/lib/config/plugins.js +++ b/lib/config/plugins.js @@ -117,6 +117,10 @@ module.exports = { } catch (err) { debug("Failed to load plugin eslint-plugin-" + pluginNameWithoutPrefix + ". Proceeding without it."); err.message = "Failed to load plugin " + pluginName + ": " + err.message; + err.messageTemplate = "plugin-missing"; + err.messageData = { + pluginName: pluginNameWithoutPrefix + }; throw err; } diff --git a/messages/plugin-missing.txt b/messages/plugin-missing.txt new file mode 100644 index 000000000000..56679528c9bc --- /dev/null +++ b/messages/plugin-missing.txt @@ -0,0 +1,9 @@ +ESLint couldn't find the plugin "eslint-plugin-<%- pluginName %>". This can happen for a couple different reasons: + +1. If ESLint is installed globally, then make sure eslint-plugin-<%- pluginName %> is also installed globally. A globally-installed ESLint cannot find a locally-installed plugin. + +2. If ESLint is installed locally, then it's likely that the plugin isn't installed correctly. Try reinstalling by running the following: + + npm i eslint-plugin-<%- pluginName %>@latest --save-dev + +If you still can't figure out the problem, please stop by https://gitter.im/eslint/eslint to chat with the team. diff --git a/package.json b/package.json index f46da5853ceb..05dfeafb4be0 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "README.md", "bin", "conf", - "lib" + "lib", + "messages" ], "repository": { "type": "git",