Skip to content

Catch TypeError from function calls and convert to FireError#654

Open
saivedant169 wants to merge 1 commit intogoogle:masterfrom
saivedant169:fix/improve-missing-arg-error-message
Open

Catch TypeError from function calls and convert to FireError#654
saivedant169 wants to merge 1 commit intogoogle:masterfrom
saivedant169:fix/improve-missing-arg-error-message

Conversation

@saivedant169
Copy link

Fixes #633

Description

When a function call raises TypeError due to missing or unexpected arguments, the exception now gets converted 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 before the function is called. But edge cases — like *args unpacking mismatches, keyword argument conflicts, or arguments that Fire's parser couldn't map — can slip through to the actual fn(*varargs, **kwargs) call in _CallAndUpdateTrace.

What changed

Wrapped the function call block (lines 679-690) in _CallAndUpdateTrace with a try/except that:

  1. Catches TypeError exceptions
  2. Checks if they're argument-related (contains "required", "missing", or "argument" in the message)
  3. Converts them to FireError for proper error display
  4. Re-raises non-argument TypeError unchanged (e.g., errors from within the function body)

Testing

  • All 91 existing tests pass (pytest fire/core_test.py fire/fire_test.py)
  • pylint fire/core.py scores 10.00/10

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
@google-cla
Copy link

google-cla bot commented Mar 16, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error message when required argument is missing

1 participant