-
Notifications
You must be signed in to change notification settings - Fork 0
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
Avoid raising bare Exception #6
base: main
Are you sure you want to change the base?
Conversation
… on exception messages)
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.
PR Summary
This PR improves exception handling throughout the LibCST codebase by replacing bare Exception
raises with more specific exception types.
- Introduced
CSTLogicError
inlibcst/_excep.py
for logical errors within CST processing - Replaced generic
Exception
raises withValueError
,CSTValidationError
,ParserSyntaxError
, andCSTLogicError
across multiple files - Updated
libcst/__init__.py
to includeCSTLogicError
in the__all__
list for easier importing - Modified error messages in various files to provide more precise information about the cause of exceptions
- Improved consistency in exception handling across different modules and components of LibCST
30 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings
raise ValueError( | ||
"Cannot have multiple star ('*') markers in a single argument " | ||
+ "list." | ||
) |
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.
style: Consider using ParserSyntaxError
instead of ValueError
for consistency with other parsing errors
raise ValueError( | ||
"Cannot have multiple slash ('/') markers in a single argument " | ||
+ "list." | ||
) |
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.
style: Consider using ParserSyntaxError
instead of ValueError
for consistency with other parsing errors
@@ -168,7 +169,7 @@ def add_param( | |||
# Example code: | |||
# def fn(**kwargs, trailing=None) | |||
# This should be unreachable, the grammar already disallows it. | |||
raise Exception("Cannot have any arguments after a kwargs expansion.") | |||
raise ValueError("Cannot have any arguments after a kwargs expansion.") |
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.
style: Consider using ParserSyntaxError
instead of ValueError
for consistency with other parsing errors
raise ValueError( | ||
"Expected a keyword argument but found a starred positional " | ||
+ "argument expansion." | ||
) |
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.
style: Consider using ParserSyntaxError
instead of ValueError
for consistency with other parsing errors
raise ValueError( | ||
"Multiple starred keyword argument expansions are not allowed in a " | ||
+ "single argument list" | ||
) |
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.
style: Consider using ParserSyntaxError
instead of ValueError
for consistency with other parsing errors
Summary
Before tackling issue Instagram#457, there are some bare Exceptions thrown from within the code.
Here is the logic for changes in Exceptions:
ValueError
when issue caused by user inputCSTValidationError
&TypeError
when issue occurs during the CST validation processParserSyntaxError
when issue occurs during the parsing processCSTLogicError
to replace all Exception which contained "Logic error" in the cause messageI'm all for changes if some Exceptions changes are not OK,
In particular, there are some
ParserSyntaxError
which may not be meaningful - with raw_line=0, raw_column=0 paramsTest Plan
Keep the current test plan.