Skip to content

Commit

Permalink
Refs facebookarchive#188, display jsonlint error log in comment as co…
Browse files Browse the repository at this point in the history
…de block
  • Loading branch information
jeffreyleeon committed Nov 28, 2016
1 parent a952918 commit f15a5fd
Showing 1 changed file with 11 additions and 1 deletion.
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 f15a5fd

Please sign in to comment.