Refactor custom rule exception tests for smaller size and better coverage.

This commit is contained in:
David Anson 2021-12-10 21:33:20 -08:00
parent e7662b11b5
commit 109e0d8cb6
3 changed files with 129 additions and 179 deletions

View file

@ -576,9 +576,10 @@ function lintContent(
try {
rule.function(params, onError);
} catch (error) {
const message = (error instanceof Error) ? error.message : error;
onError({
"lineNumber": 1,
"detail": `This rule threw an exception: ${error.message}`
"detail": `This rule threw an exception: ${message}`
});
}
} else {
@ -590,7 +591,7 @@ function lintContent(
ruleList.forEach(forRule);
} catch (error) {
cache.clear();
return callback(error);
return callback((error instanceof Error) ? error : new Error(error));
}
cache.clear();
// Sort results by rule name by line number