Skip to content

Commit 3dd14fd

Browse files
authored
Add more context to CLI error messages (#531)
* feat: add more text to CLI error messages * chore: update changelog
1 parent c5ca8b1 commit 3dd14fd

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
- Support for fetching catalog queryables [#477](https://github.com/stac-utils/pystac-client/pull/477)
1414
- PySTAC Client specific warnings [#480](https://github.com/stac-utils/pystac-client/pull/480)
1515
- Support for fetching and merging a selection of queryables [#511](https://github.com/stac-utils/pystac-client/pull/511)
16+
- Better error messages for the CLI [#531](https://github.com/stac-utils/pystac-client/pull/531)
1617

1718
### Changed
1819

pystac_client/cli.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import warnings
88
from typing import Any, Dict, List, Optional
99

10+
from pystac import STACTypeError
11+
1012
from .client import Client
1113
from .conformance import ConformanceClasses
1214
from .item_search import OPS
@@ -50,7 +52,7 @@ def search(
5052
return 0
5153

5254
except Exception as e:
53-
print(e)
55+
print(f"ERROR: {e}")
5456
return 1
5557

5658

@@ -64,8 +66,15 @@ def collections(client: Client, save: Optional[str] = None) -> int:
6466
else:
6567
print(json.dumps(collections_dicts))
6668
return 0
69+
except STACTypeError as e:
70+
print(f"ERROR: {e}")
71+
print(
72+
f"The client at {client.self_href} is OK, but one or more of the "
73+
"collections is invalid."
74+
)
75+
return 1
6776
except Exception as e:
68-
print(e)
77+
print(f"ERROR: {e}")
6978
return 1
7079

7180

@@ -329,7 +338,7 @@ def cli() -> int:
329338
)
330339

331340
except Exception as e:
332-
print(e, file=sys.stderr)
341+
print(f"ERROR: {e}", file=sys.stderr)
333342
return 1
334343

335344
if cmd == "search":

0 commit comments

Comments
 (0)