Skip to content

Commit

Permalink
Added better error handling when running the rubocop command.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmecham committed Mar 27, 2020
1 parent f8a8197 commit 4939ff3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions RuboCop.novaextension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## UNRELEASED

- Added better error handling when running the `rubocop` command so that we
don't completely blow up when there are configuration warnings and errors.

## Version 0.4.2

- Fixed invocation of bundled RuboCop by executing it in the full shell
Expand Down
25 changes: 17 additions & 8 deletions Source/Scripts/RuboCopProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ class RuboCopProcess {
if (!process) return;

let output = "";
let errorOutput = "";
process.onStdout(line => output += line);
process.onStderr(line => output += line);
process.onStderr(line => errorOutput += line);
process.onDidExit(status => {
// See: https://github.com/rubocop-hq/rubocop/blob/master/manual/basic_usage.md#exit-codes
status >= 2 ? this.handleError(output) : this.handleOutput(output);
status >= 2 ? this.handleError(errorOutput) : this.handleOutput(output, errorOutput);
});

process.start();
Expand All @@ -124,14 +125,22 @@ class RuboCopProcess {
console.error(error);
}

handleOutput(output) {
const parsedOutput = JSON.parse(output);
const offenses = parsedOutput["files"][0]["offenses"];
handleOutput(output, warningOutput) {
if (warningOutput) {
console.warn(warningOutput);
}

// TODO: Enable a "Debug" Preference
// console.info(JSON.stringify(offenses, null, " "));
try {
const parsedOutput = JSON.parse(output);
const offenses = parsedOutput["files"][0]["offenses"];

// TODO: Enable a "Debug" Preference
// console.info(JSON.stringify(offenses, null, " "));

this.offenses = offenses.map(offense => new Offense(offense));
this.offenses = offenses.map(offense => new Offense(offense));
} catch(error) {
console.error(error);
}

if (this._onCompleteCallback) {
this._onCompleteCallback(this.offenses);
Expand Down

0 comments on commit 4939ff3

Please sign in to comment.