Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #414 from AtomLinter/arcanemagus/report-errors
Browse files Browse the repository at this point in the history
Report when flake8 crashes!
  • Loading branch information
Arcanemagus committed Apr 25, 2017
2 parents 6c39c95 + dce14bf commit 8bdc062
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib/main.js
Expand Up @@ -181,12 +181,27 @@ export default {
const options = {
stdin: fileText,
cwd: path.dirname(textEditor.getPath()),
stream: 'both',
ignoreExitCode: true,
timeout: forceTimeout,
uniqueKey: `linter-flake8:${filePath}`,
};

const result = await helpers.exec(execPath, parameters, options);
let result;
try {
result = await helpers.exec(execPath, parameters, options);
} catch (e) {
const pyTrace = e.message.split('\n');
const pyMostRecent = pyTrace[pyTrace.length - 1];
atom.notifications.addError('Flake8 crashed!', {
detail: 'linter-flake8:: Flake8 threw an error related to:\n' +
`${pyMostRecent}\n` +
"Please check Atom's Console for more details",
});
// eslint-disable-next-line no-console
console.error('linter-flake8:: Flake8 returned an error', e.message);
// Tell Linter to not update any current messages it may have
return null;
}

if (result === null) {
// Process was killed by a future invocation
Expand All @@ -198,13 +213,9 @@ export default {
return null;
}

if (result.stderr && result.stderr.length && atom.inDevMode()) {
// eslint-disable-next-line no-console
console.log(`flake8 stderr: ${result.stderr}`);
}
const messages = [];

let match = parseRegex.exec(result.stdout);
let match = parseRegex.exec(result);
while (match !== null) {
// Note that these positions are being converted to 0-indexed
const line = Number.parseInt(match[1], 10) - 1 || 0;
Expand All @@ -226,7 +237,7 @@ export default {
execPath, match, filePath, textEditor, point));
}

match = parseRegex.exec(result.stdout);
match = parseRegex.exec(result);
}
// Ensure that any invalid point messages have finished resolving
return Promise.all(messages);
Expand Down

0 comments on commit 8bdc062

Please sign in to comment.