-
Notifications
You must be signed in to change notification settings - Fork 346
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: add a dedicated exception for cli errors #5649
Merged
Merged
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9802f24
try out expected exceptions for cli error handling
hamidzr 8d18df5
migrate
hamidzr 2be9992
define some expected types
hamidzr 0170709
add CliHandler type alias
hamidzr 1653fc1
add support for a msg and stacktrace. add a demo.
hamidzr 5f82a76
update aws error reporting
hamidzr 771303e
update the comments and stack trace color
hamidzr 650b534
no need for the decorator
hamidzr 638a25a
take out sys.exit usage
hamidzr 27fac70
take out report_cli_error
hamidzr dca27bd
use separate messaging for cli arg errors
hamidzr 314f9d2
Revert "use separate messaging for cli arg errors"
hamidzr 48db7f9
give cli errors names
hamidzr 7fea04e
update import path
hamidzr b331017
fix an argument mismatch
hamidzr bbbb9c9
switch to ArgumentError for CLI arg errors
hamidzr f07fb93
add missing closing periods to error messages
hamidzr 703e9f2
lint
hamidzr b0be62d
avoid printing e_stack by default
hamidzr b2dbc3f
assign exit code 2 for arg errors
hamidzr File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,43 @@ | ||
from typing import Any, Optional | ||
|
||
|
||
class FeatureFlagDisabled(Exception): | ||
""" | ||
Exception indicating that there is a currently disabled feature flag | ||
that is required to use a feature | ||
""" | ||
|
||
pass | ||
|
||
|
||
class CliError(Exception): | ||
""" | ||
Base class for all CLI errors. | ||
""" | ||
|
||
name: str | ||
|
||
def __init__( | ||
self, message: str, e_stack: Optional[Exception] = None, exit_code: int = 1 | ||
) -> None: | ||
""" | ||
Args: | ||
- e_stack: The exception that caused this error. | ||
- exit_code: The exit code to use when exiting the CLI. | ||
""" | ||
super().__init__(message) | ||
self.name = "Error" | ||
self.exit_code = exit_code | ||
self.e_stack = e_stack | ||
self.message = message | ||
|
||
|
||
class CliArgError(CliError): | ||
hamidzr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Exception indicating that there was a problem with the arguments | ||
passed to the CLI. | ||
""" | ||
|
||
def __init__(self, message: str, *args: Any, **kwargs: Any) -> None: | ||
super().__init__(message, *args, **kwargs) | ||
self.name = "Input Error" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we don't want to always have this prefix.
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.
any thoughts on this? I took out the prefix since that'd be the least change in output. we can opt to add them back later
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.
Exception class name as a prefix? yeah I suppose we can remove it. if it's the same for all errors there's not much value in 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.
I had it be separate for argument errors. I guess it could be useful if you wanted to make the cli output a bit more machine readable but it has its own tradeoffs we don't need to worry about it here