Skip to content
This repository has been archived by the owner on Nov 28, 2018. It is now read-only.

Commit

Permalink
Display jsonlint error in parsing .mention-bot file with syntax error (
Browse files Browse the repository at this point in the history
…#190)

* Refs #188, add jsonlint library

* Refs #188, display jsonlint error log in comment as code block
  • Loading branch information
jeffreyleeon authored and vjeux committed Nov 29, 2016
1 parent 58bda60 commit c7faf14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
12 changes: 11 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -103,6 +104,7 @@ function getRepoConfig(request) {
var data = JSON.parse(result.data);
resolve(data);
} catch (e) {
e.repoConfig = result.data;
reject(e);
}
});
Expand Down Expand Up @@ -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);
}
});
Expand Down

0 comments on commit c7faf14

Please sign in to comment.