Skip to content

Improve error message when required argument is missing #633

@markrahimi

Description

@markrahimi

Description

When a required function argument is not provided via the command line, Python Fire raises a generic TypeError that doesn't clearly indicate which argument is missing or how to provide it.

Current Behavior

$ python my_script.py greet
TypeError: greet() missing 1 required positional argument: 'name'

Expected Behavior

A more user-friendly error message that would guide the user:

$ python my_script.py greet
Error: Missing required argument 'name'
Usage: my_script.py greet <name>

Motivation

This would significantly improve the user experience, especially for new users who are unfamiliar with Python tracebacks. Clear error messages are crucial for CLI tools.

Environment

  • Python Fire version: 0.7.1
  • Python version: 3.11
  • OS: macOS

Possible Solution

Catch TypeError exceptions in the argument parsing logic and check if they're related to missing arguments, then provide a more descriptive message with usage hints.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions