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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ado-improvements-1): Refactor reporter errors #1046
Conversation
})().catch((error) => { | ||
console.log('Exception thrown in extension: ', error); | ||
process.exit(1); | ||
console.log('##[error][Exception] Exception thrown in extension: ', 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.
I was about to ask if we should use a logger method instead here, but if I understand right, we don't have access to it in this scope
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's correct. We get a Logger further upstream, but it a failure occurs before it's initialized, using console.log ensures that we can always produce the output
})().catch((error) => { | ||
console.log('Exception thrown in action: ', error); | ||
process.exit(1); | ||
console.log('::error::[Exception] Exception thrown in extension: ', 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.
This uses the action error syntax described at https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message. I'll create a separate PR that uses this through the Logger
API
Details
As called out in #950, we throw an
Error
if a scan fails, then we log theError
twice. To a user, it looks like our tool has crashed, when in reality it's an accessibility error that the user should fix. This PR does the following to improve this:ProgressReporter.failRun
used to throw an Error to force the program to fail. The new code merely sets a flag inProgressReporter.failRun
, then a new API,ProgressReporter.didScanSucceed
, serves as an indicator of whether or not the scan succeeded.ProgressReporter.failRun
with a message is now responsible for logging the error message viaLogger.logError
orLogger.trackException
, depending on the circumstance. With this change order of theProgressReporter
objects no longer matters, so I removed the associated comment.Scanner.scan
now returns aPromise<boolean>
instead of aPromise<void>
. The resolved value of the promise indicates user action. A successful value (true) means that no corrective action is needed by the user. A failed value (false) means that the user need to take some corrective action.ExitCode.ScanCompletedNoUserActionIsNeeded
) means that the scan completed successfully and no corrective user action is needed.ExitCode.ScanCompletedUserActionIsNeeded
) means that the scan completed successfully, but corrective user action is needed.ExitCode.ScanFailedToComplete
) means that the scan failed to complete. This will always be accompanied by a log of the Error that led to the failure.I also wordsmithed a couple of error messages while I was updating the code and associated tests. A couple of linting issues were also flagged, so I tidied them up.
Motivation
Make progress toward #950
Before and after
Output before this change--baseline file doesn't match the scan results. Notice the duplicated stack dumps and the fact that the error message is lost as the message of the stack dump
Output after this change--baseline file doesn't match the scan results. Notice that the stack dumps are removed and that the message is called out with an `##[error]` tag near the end of the output
Context
Pull request checklist
yarn test
)<rootDir>/test-results/unit/coverage
yarn precheckin
)