Skip to content

Graceful Error Handling #81

@krowvin

Description

@krowvin

CLI Script

cwms-cli

Feature Proposal

CWMS-Python does a good job at catching errors and reporting them. But for something like the CLI I think we should consider catching them, logging them to disk(?), and printing just the hint?

Example is when we expect a 404 because we are checking with the retrieve cli command to see if after deleting we actually deleted something.

404 is valid yet it throws the entire stack trace in the CLI, clogging it.

REDACTED relevant log output

2025-12-05 23:02:31;DEBUG;http://localhost:8082 "GET /cwms-data/timeseries/group/Test-monthlychartsgroup2?office=SWT&category-id=Test-monthlycharts2&category-office-id=SWT&group-office-id=SWT HTTP/1.1" 404 116
2025-12-05 23:02:31;ERROR;CDA Error: response=<Response [404]>
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "redacted\cwms-cli.exe\__main__.py", line 6, in <module>
    sys.exit(cli())
             ~~~^^
  File "redactedclick\core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "redactedclick\core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "redactedclick\core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "redactedclick\core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "redactedclick\core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "redactedclick\core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "redactedclick\core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "redacted\commands_cwms.py", line 363, in timeseries_group_download
    retrieve_cmd(**kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^
  File "redacted\timeseries\group.py", line 205, in retrieve_cmd
    retrieve_group(
    ~~~~~~~~~~~~~~^
        group_id=group_id,
        ^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
        dest_dir=dest_dir,
        ^^^^^^^^^^^^^^^^^^
    )
    ^
  File "redacted\timeseries\group.py", line 30, in retrieve_group
    group = cwms.get_timeseries_group(
        group_id=group_id,
    ...<3 lines>...
        office_id=office,
    )
  File "redacted\timeseries\timeseries_group.py", line 47, in get_timeseries_group
    response = api.get(endpoint=endpoint, params=params, api_version=1)
  File "redacted\api.py", line 287, in get
    raise ApiError(response)
cwms.api.ApiError: CWMS API Error (http://localhost:8082/cwms-data/timeseries/group/Test-monthlychartsgroup2?office=SWT&category-id=Test-monthlycharts2&category-office-id=SWT&group-office-id=SWT) Not Found.

        {"message":"Unable to find group based on parameters given","incidentIdentifier":"5936987993404746804","details":{}}

        404 Not Found
        Unable to find group based on parameters given
        May be the result of an empty query.

Related Context or Links

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions