-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Handled unhandled exception to show bug report message #4565
Conversation
samcli/commands/exceptions.py
Outdated
msg = ( | ||
f'An unexpected error was encountered while executing "{self._command}".\n' | ||
"To create a bug report, follow the Github issue template below:\n" | ||
f"{url}" | ||
) |
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 feel like this could make it easier to have duplicate issues (multiple issues asking about the same problem). Could we first give them a link to search issues with the same title that this issue would be auto-populated?
For example, for the example in your PR description it would be:
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.
Updated the messaging
samcli/lib/telemetry/metric.py
Outdated
@@ -148,16 +148,18 @@ def wrapped(*args, **kwargs): | |||
# Execute the function and capture return value. This is returned back by the wrapper | |||
# First argument of all commands should be the Context | |||
return_value = func(*args, **kwargs) | |||
except UserException as ex: | |||
except (UserException, click.BadOptionUsage, click.BadArgumentUsage, click.BadParameter) as ex: |
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 did we add more exceptions to catch?
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 I understand now, but why did we add only these? Should we just catch all click exceptions? Or at least a few others that are here: https://click.palletsprojects.com/en/8.1.x/api/#exceptions
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.
Good catch. I missed click.UsageError
.
The idea of grouping these click exceptions together is that these exceptions should be fixable by users. Any user-fixable-exception that is thrown within the call stacks wrapped by @track_command
should be caught by this line. I don't want to catch click.ClickException
in general because that could be over-catching. I'd rather an exception to be an Unhandled Exception by default.
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.
Gotcha. What about NoSuchOption
?
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 don't see any reason we should use NoSuchOption
in our own code. So don't think we should include it.
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.
Maybe I'm misunderstanding but wouldn't NoSuchOption
be raised by click
when a user provides an option that doesn't exist? Or are you saying that wouldn't even reach this code anyway?
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 won't reach this code. We should have all @option
declared before @track_command
exit_reason = type(ex).__name__ | ||
else: | ||
# TODO (hawflau): review exitcode meaning. We now understand exitcode 1 as errors fixable by users. | ||
exit_code = 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 did this change from ex.exit_code
to 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.
click.BadOptionUsage
and other click exception caught here come with exitcode=2 by default. In our Telemetry, they were, however, classified as 255 (as we didn't catch any them). Today, we only have 1 and 255 exitcodes in our Telemetry. We should revisit the exitcode meaning someday. But for now, re-classifying them as exitcode 1 seems more correct to me.
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.
But why not use whatever actual exit code is thrown, instead of only either 1 or 255?
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 now I don't want to introduce new exitcode (e.g. 2) into Telemetry, until we have clearer understandings about how we want to use the exitcode. Today, click.BadOptionUsage
and click.UsageError
(maybe a couple other user-fixable exceptions as well) go into Telemetry with exitcode 255, which is certainly incorrect. I just want to fix this first.
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.
Left a few questions and suggestions
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.
Looks good to me. Thanks for handling the feedback.
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.
Thanks! do we have an idea of what kind of use cases would cause Unhandled Exceptions today?
There are two cases from my observation:
|
* Handled unhandled exception to show bug report message * Fix linting issues * run black reformat * Update message text and add unit test * Run black reformat * add test cases * Update actual exitcode of UnhandledException to 1 to not break existing behavior * remove unused import * address feedback * Update messaging * Update Unit Tests GH Action to make sure Bug_report.md exists * Update bug report * Update Bug Report template * fix typo * Update wording * update test
Which issue(s) does this change fix?
N/A
Why is this change necessary?
To show a message that guides customers to create a bug report in case of unhandled exceptions
How does it address the issue?
click.BadOptionUsage
,click.BadArgumentUsage
,click.BadParameter
andclick.UsageError
into the handling ofUserException
Example:
What side effects does this change have?
The actual exitcode of the execution in case of
UnhandledException
is still 1. This is to not break existing behavior. We only report 255 to Telemetry.Mandatory Checklist
PRs will only be reviewed after checklist is complete
make pr
passesmake update-reproducible-reqs
if dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.