From ba937f89fa9609316741a6b9238faa3ab8667861 Mon Sep 17 00:00:00 2001 From: Mathias Schreck Date: Tue, 16 Aug 2016 19:40:23 +0200 Subject: [PATCH 1/4] Add eslint to detect unhandled callback errors --- .eslintignore | 20 ++++++++++++++++++++ .eslintrc.json | 6 ++++++ package.json | 1 + 3 files changed, 27 insertions(+) create mode 100644 .eslintignore create mode 100644 .eslintrc.json diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000..0799652254 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,20 @@ +node_modules/ +public/src/nodebb.min.js +*.sublime-project +*.sublime-workspace +.project +.vagrant +.DS_Store +logs/ +/public/templates +/public/uploads +/public/sounds +/public/vendor +/public/nodebb.min.js +/public/acp.min.js +/public/src/modules/string.js +.idea/ +.vscode/ +*.ipr +*.iws +/coverage diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000000..f8ca19c4cb --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,6 @@ +{ + "rules": { + "handle-callback-err": [ "error", "^(e$|(e|(.*(_e|E)))rr)" ] + } +} + diff --git a/package.json b/package.json index 56323b7773..e581eeb255 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,7 @@ "xregexp": "~3.1.0" }, "devDependencies": { + "eslint": "^3.4.0", "grunt": "~0.4.5", "grunt-contrib-watch": "^1.0.0", "istanbul": "^0.4.2", From 159da18e9f84ccea651c515e865afb552c84effb Mon Sep 17 00:00:00 2001 From: Mathias Schreck Date: Tue, 16 Aug 2016 19:40:39 +0200 Subject: [PATCH 2/4] Add npm script to run eslint --- .gitignore | 3 ++- package.json | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a83a93d01f..510c95a201 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ provision.sh *.komodoproject .DS_Store feeds/recent.rss +.eslintcache logs/ @@ -51,4 +52,4 @@ tx.exe .transifexrc ##Coverage output -coverage \ No newline at end of file +coverage diff --git a/package.json b/package.json index e581eeb255..6b4ad6bfcf 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "main": "app.js", "scripts": { "start": "node loader.js", + "lint": "eslint --cache .", "test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- ./tests -t 10000" }, "dependencies": { From 824c6d93626c5bf80862be1ac9c6fd417db1cb24 Mon Sep 17 00:00:00 2001 From: Mathias Schreck Date: Tue, 16 Aug 2016 19:41:02 +0200 Subject: [PATCH 3/4] Run eslint as part of npm test --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 6b4ad6bfcf..00f6fb2f30 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "scripts": { "start": "node loader.js", "lint": "eslint --cache .", + "pretest": "npm run lint", "test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- ./tests -t 10000" }, "dependencies": { From fef9ec7ad65b8ed9da7d65c67bfc5267f9ba4c95 Mon Sep 17 00:00:00 2001 From: Mathias Schreck Date: Mon, 5 Sep 2016 11:52:35 +0200 Subject: [PATCH 4/4] Fix unhandled callback errors --- public/src/admin/settings/email.js | 4 ++++ src/controllers/authentication.js | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/public/src/admin/settings/email.js b/public/src/admin/settings/email.js index 02edfffcaa..e404099800 100644 --- a/public/src/admin/settings/email.js +++ b/public/src/admin/settings/email.js @@ -79,6 +79,10 @@ define('admin/settings/email', ['admin/settings'], function(settings) { } socket.emit('meta.getServerTime', {}, function(err, now) { + if (err) { + return app.alertError(err.message); + } + now = new Date(now); $('#serverTime').text(now.toString()); diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js index e0dc2f5649..ce2c652b6a 100644 --- a/src/controllers/authentication.js +++ b/src/controllers/authentication.js @@ -381,7 +381,9 @@ authenticationController.localLogin = function(req, username, password, next) { if (result.banned) { // Retrieve ban reason and show error return user.getLatestBanInfo(uid, function(err, banInfo) { - if (banInfo.reason) { + if (err) { + next(err); + } else if (banInfo.reason) { next(new Error('[[error:user-banned-reason, ' + banInfo.reason + ']]')); } else { next(new Error('[[error:user-banned]]'));