Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: improve crash reporting (fixes #11304) #11463

Merged
merged 1 commit into from Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/linter.js
Expand Up @@ -747,10 +747,15 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser
nodeQueue.forEach(traversalInfo => {
currentNode = traversalInfo.node;

if (traversalInfo.isEntering) {
eventGenerator.enterNode(currentNode);
} else {
eventGenerator.leaveNode(currentNode);
try {
if (traversalInfo.isEntering) {
eventGenerator.enterNode(currentNode);
} else {
eventGenerator.leaveNode(currentNode);
}
} catch (err) {
err.currentNode = currentNode;
throw err;
}
});

Expand Down Expand Up @@ -901,8 +906,15 @@ module.exports = class Linter {
options.filename
);
} catch (err) {
err.message += `\nOccurred while linting ${options.filename}`;
debug("An error occurred while traversing");
debug("Filename:", options.filename);
if (err.currentNode) {
const { line } = err.currentNode.loc.start;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get column information here too?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could. The reason I didn't include it is because it's even less accurate than the line number - it won't always point exactly to the spot that caused the crash. Even the line number won't always do that, depending on how the rule is implemented.


debug("Line:", line);
err.message += `:${line}`;
}
debug("Parser Options:", parserOptions);
debug("Parser Path:", parserName);
debug("Settings:", settings);
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/linter.js
Expand Up @@ -99,7 +99,7 @@ describe("Linter", () => {

assert.throws(() => {
linter.verify(code, config, filename);
}, "Intentional error.");
}, `Intentional error.\nOccurred while linting ${filename}:1`);
});

it("does not call rule listeners with a `this` value", () => {
Expand Down Expand Up @@ -4381,7 +4381,7 @@ describe("Linter", () => {

assert.throws(() => {
linter.verify("0", { rules: { "test-rule": "error" } });
}, /Fixable rules should export a `meta\.fixable` property.$/u);
}, /Fixable rules should export a `meta\.fixable` property.\nOccurred while linting <input>:1$/u);
});

it("should not throw an error if fix is passed and there is no metadata", () => {
Expand Down