Skip to content

[TD-016] CLI date argument validation happens late #13

@LFigg

Description

@LFigg

Description

Date format validation happens implicitly when passed to APIs, leading to cryptic error messages late in execution.

Location

  • File: cost_collect.py around line 716-720

Impact

  • Poor user experience
  • Wasted time waiting for collection to fail
  • Cryptic error messages from downstream APIs

Suggested Fix

Add early validation in argument parser:

def valid_date(date_string: str) -> str:
    """Validate date format YYYY-MM-DD."""
    try:
        datetime.strptime(date_string, '%Y-%m-%d')
        return date_string
    except ValueError:
        raise argparse.ArgumentTypeError(
            f"Invalid date format: '{date_string}'. Expected YYYY-MM-DD"
        )

parser.add_argument('--start-date', type=valid_date, ...)
parser.add_argument('--end-date', type=valid_date, ...)

Priority

Low

Source

TECH_DEBT.md - TD-016

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions