Skip to content

[CC-005] Missing date validation in cost_collect.py #17

@LFigg

Description

@LFigg

Description

Date parameters are not validated early, leading to cryptic API errors when invalid dates are provided.

Location

  • File: cost_collect.py - CLI argument handling

Impact

  • Poor user experience
  • Time wasted on failed collection
  • Cryptic error messages from cloud APIs

Note

This overlaps with TD-016 but is specific to cost_collect.py.

Suggested Fix

Add validation in argument parser:

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

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

Also validate that start_date < end_date and range is not too large.

Priority

Medium

Source

cost_collect.py code review - CC-005

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions