-
Notifications
You must be signed in to change notification settings - Fork 68
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
fix(cli): provide a more robust error message if analysis fails #421
Conversation
--include
and --exclude
to throw error on invalid / not found CSS selectors
@@ -91,7 +92,8 @@ const testPages = async ( | |||
|
|||
/* istanbul ignore if */ | |||
if (err) { | |||
return reject(err); | |||
console.error(error(err)); | |||
process.exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't reject(err)
allow the caller to handle the error on their own? I don't understand how/why this fixes anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like the problem is how we're handing rejections then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the issue is here:
What is %j \n $s
supposed to do? I don't see %j
listed in the Console API's substitution strings, and $s
isn't a thing.
Instead, that should probably be:
if (!showErrors) {
console.error(error('An error occurred while testing this page.'));
} else {
console.error(error('Error: %s \n %s'), e.message, e.stack);
}
Which will still look weird, since the stack trace is weirdly indented (and on the next line), but that isn't what the linked issue is about 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the error is here https://github.com/dequelabs/axe-core-npm/blob/v4.3.2/packages/cli/src/lib/axe-test-urls.ts#L87 we use err: string
so we don't have access to e.message
or e.stack
to do the the string formatting you mentioned
edit: %j
JSON. Replaced with the string '[Circular]' if the argument contains circular references. (source)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the types on the line you linked are correct (err: string
), then we should do something like:
axe.analyze((err: Error | string | null, results: AxeResults) => {
if (config.timer) {
events?.endTimer('axe-core execution time');
}
/* istanbul ignore if */
if (err) {
const error = typeof err === 'string' ? new Error(err) : err
return reject(error);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like that type is wrong, as we pass back the whole Error
(unless in legacy/callback mode).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, looking at it a bit more, the type for the callback function should be Error | null
and not string | null
. So we can access e.message
etc. However, your work around does allow the user to handle the error with --show-errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the type for that function is wrong. IMO it should be changed/corrected.
However, if we want a very simple fix for the issue at hand, we could just fix the console.error()
call in src/bin/index.ts
:
if (!showErrors) {
console.error(error('An error occurred while testing this page.'));
} else {
console.error(error('Error: %s'), e);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference issue has been raised: #422
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I support the change, I don't see how the title describes what you changed, or how this closes the issue.
--include
and --exclude
to throw error on invalid / not found CSS selectors
The use of
--include
and providing an non-existent or invalid CSS selector would not notify user that was the case:Providing an non-existent or invalid CSS selector will now notify the user of said error:
Closes issue: #207