Catch TypeError from function calls and convert to FireError#654
Open
saivedant169 wants to merge 1 commit intogoogle:masterfrom
Open
Catch TypeError from function calls and convert to FireError#654saivedant169 wants to merge 1 commit intogoogle:masterfrom
saivedant169 wants to merge 1 commit intogoogle:masterfrom
Conversation
When a function call raises TypeError due to missing or unexpected arguments, convert it to FireError so it flows through Fire's error display pipeline (error message + usage text) instead of crashing with a raw Python traceback. The existing _ParseArgs validation catches most missing-argument cases, but edge cases (e.g. *args unpacking mismatches, argument type conflicts) can slip through to the actual fn() call. Only argument-related TypeErrors are caught — other TypeErrors (e.g. from the function body itself) are re-raised unchanged. Fixes google#633
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #633
Description
When a function call raises
TypeErrordue to missing or unexpected arguments, the exception now gets converted toFireErrorso it flows through Fire's error display pipeline (error message + usage text) instead of crashing with a raw Python traceback.The existing
_ParseArgsvalidation catches most missing-argument cases before the function is called. But edge cases — like*argsunpacking mismatches, keyword argument conflicts, or arguments that Fire's parser couldn't map — can slip through to the actualfn(*varargs, **kwargs)call in_CallAndUpdateTrace.What changed
Wrapped the function call block (lines 679-690) in
_CallAndUpdateTracewith a try/except that:TypeErrorexceptionsFireErrorfor proper error displayTypeErrorunchanged (e.g., errors from within the function body)Testing
pytest fire/core_test.py fire/fire_test.py)pylint fire/core.pyscores 10.00/10