diff --git a/package.json b/package.json index 23a1421..33fa01f 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "flow-bin": "^0.18.1", "github": "^2.1.0", "jest-cli": "^0.7.1", + "jsonlint": "^1.6.2", "minimatch": "^3.0.0", "node-schedule": "^1.0.0" } diff --git a/server.js b/server.js index d1e8ba7..c0cbfc2 100644 --- a/server.js +++ b/server.js @@ -19,6 +19,7 @@ var util = require('util'); var schedule = require('./schedule.js'); var GitHubApi = require('github'); +var jsonlint = require('jsonlint'); var CONFIG_PATH = '.mention-bot'; @@ -103,6 +104,7 @@ function getRepoConfig(request) { var data = JSON.parse(result.data); resolve(data); } catch (e) { + e.repoConfig = result.data; reject(e); } }); @@ -166,12 +168,20 @@ async function work(body) { }).catch(function(e) { if (e instanceof SyntaxError && repoConfig.actions.indexOf(data.action) !== -1) { // Syntax error while reading custom configuration file + var errorLog = ''; + try { + jsonlint.parse(e.repoConfig) + } catch(err) { + errorLog = err; + } var message = 'Unable to parse mention-bot custom configuration file due to a syntax error.\n' + 'Please check the potential root causes below:\n\n' + '1. Having comments\n' + '2. Invalid JSON type\n' + - '3. Having extra "," in the last JSON attribute'; + '3. Having extra "," in the last JSON attribute\n\n' + + 'Error message:\n' + + '```\n' + errorLog + '\n```'; createComment(data, message); } });