Skip to content

Commit

Permalink
Update: Better error message for plugins (refs #5221)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Feb 22, 2016
1 parent 40fec58 commit 8f6c2e7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
21 changes: 20 additions & 1 deletion bin/eslint.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,12 +29,31 @@ if (debug) {


// now we can safely include the other modules that use debug // now we can safely include the other modules that use debug
var concat = require("concat-stream"), var concat = require("concat-stream"),
cli = require("../lib/cli"); cli = require("../lib/cli"),
path = require("path"),
fs = require("fs");


//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Execution // 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) { if (useStdIn) {
process.stdin.pipe(concat({ encoding: "string" }, function(text) { process.stdin.pipe(concat({ encoding: "string" }, function(text) {
try { try {
Expand Down
4 changes: 4 additions & 0 deletions lib/config/plugins.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ module.exports = {
} catch (err) { } catch (err) {
debug("Failed to load plugin eslint-plugin-" + pluginNameWithoutPrefix + ". Proceeding without it."); debug("Failed to load plugin eslint-plugin-" + pluginNameWithoutPrefix + ". Proceeding without it.");
err.message = "Failed to load plugin " + pluginName + ": " + err.message; err.message = "Failed to load plugin " + pluginName + ": " + err.message;
err.messageTemplate = "plugin-missing";
err.messageData = {
pluginName: pluginNameWithoutPrefix
};
throw err; throw err;
} }


Expand Down
9 changes: 9 additions & 0 deletions messages/plugin-missing.txt
Original file line number Original file line Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"README.md", "README.md",
"bin", "bin",
"conf", "conf",
"lib" "lib",
"messages"
], ],
"repository": { "repository": {
"type": "git", "type": "git",
Expand Down

0 comments on commit 8f6c2e7

Please sign in to comment.