CLI: invalid --geom/--geometry value prints a traceback and exits 1 instead of a usage error
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 72/100
Rechercherichtung
Beginne mit Geometry.convert in planet/cli/types.py und check_geom in planet/cli/validators.py; lies dann test_item_coverage_invalid_geometry in tests/integration/test_data_cli.py. Reproduziere ungültige Dateien, fehlerhaftes JSON, ungültiges GeoJSON und leere Werte mit den CLI-Tests. Fertig ist die Arbeit, wenn ungültige Werte bei den aufgeführten Befehlen einen sauberen Nutzungsfehler mit dem vorgesehenen Exit-Code auslösen und die Regressionstests bestehen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Expected behavior
An invalid --geom or --geometry value gives a one-line usage error and exit code 2. planet data filter --geom nofile.json already does this for a missing file and for malformed JSON:
Error: Invalid value for '--geom': File not found.
DESIGN.md lists exit code 2 for "invalid syntax or unknown or invalid parameter".
For GeoJSON that parses but fails validation (bad coordinate, open ring), data filter prints a clean one-line Error: Each linear ring must contain at least 4 positions but exits 1, because it validates inside the command body (translate_exceptions). Whether that case should exit 2 or 1 is a design choice. The change proposed below makes it exit 2, matching the other invalid-parameter errors, but a clean one-line error is the main point.
Actual behavior (describe the problem)
A value that is not a valid inline geometry prints a Python traceback (38 to 51 lines, depending on the input) and exits 1. This happens for a mistyped file name, a malformed inline JSON string, and GeoJSON that fails validation (bad coordinate, open ring). All eight commands that take the option do it: data search, data search-create, data search-update, data item-coverage, subscriptions request-catalog, subscriptions request-source, mosaics search and mosaics download.
For a mistyped file name or malformed JSON, the last line is also wrong: FeatureError: Expected scheme pl:features. No feature reference was passed.
An empty value (--geom "", for example from an unset shell variable) is dropped. It parses to None, so data search sends no geometry filter. I checked this by parsing the arguments only; nothing was sent. subscriptions request-catalog --geometry "" fails with TypeError: 'NoneType' object is not subscriptable.
Cause:
Geometry.convertinplanet/cli/types.pytriesJSON(), then falls back toCommaSeparatedString(), which accepts any non-empty string. The real error ("File not found", "JSON string is not valid JSON") is dropped and the string is treated as a feature reference. If both types fail, it returnsNone. The fallback was added in 0b2ce07 ("Support feature refs as strings"), first released in 2.10.0.check_geominplanet/cli/validators.pyruns as a click callback while arguments are parsed.translate_exceptionswraps only the command body, so theFeatureErrororGeoJSONErrorit raises is never turned into a click error.
test_item_coverage_invalid_geometry in tests/integration/test_data_cli.py does not catch this. It asserts exit_code == 1, which CliRunner also reports for an unhandled exception.
Catching PlanetError in check_geom and raising click.BadParameter removes the traceback. Falling back to feature references only when the value starts with pl: restores the real file and JSON messages and rejects the empty value. That test then needs exit_code == 2, like the other invalid-parameter tests. With that change on main, all eight commands print the usage error and exit 2, and pytest tests passes (919 tests).
I can send a PR.
Related Issues
None found. #337 (robust GeoJSON validation) is related but asks for more validation, not for these errors to be reported cleanly. #384 (closed) concluded that the exit codes in DESIGN.md are adequate.
Workaround
The command fails before any request is sent. For a GeoJSON error, the last line of the traceback is correct. For a file or JSON error it is misleading, so check the file name and JSON first. planet data filter --geom <file> reports file and JSON errors correctly.
Minimum, Complete, Viable Code Sample
No API key or network is needed. It fails while arguments are parsed.
> planet data search PSScene --geom nofile.json
Traceback (most recent call last):
File ".../bin/planet", line 12, in <module>
sys.exit(main())
...
File ".../planet/cli/validators.py", line 26, in check_geom
geoms.update(geojson.as_geom_or_ref(geom))
File ".../planet/geojson.py", line 60, in as_geom_or_ref
return as_ref(data)
File ".../planet/geojson.py", line 102, in as_ref
data = convert_ref_to_dict(data)
File ".../planet/geojson.py", line 91, in convert_ref_to_dict
if validate_ref(data):
File ".../planet/geojson.py", line 75, in validate_ref
raise FeatureError("Expected scheme pl:features")
planet.exceptions.FeatureError: Expected scheme pl:features
> echo $?
1
Last line of the output for other inputs:
> planet data search PSScene --geom '{"type": "Polygon"'
planet.exceptions.FeatureError: Expected scheme pl:features
> planet data search PSScene --geom '{"type":"Point","coordinates":[1,"a"]}'
planet.exceptions.GeoJSONError: Not a GeoJSON coordinate value
> planet data search PSScene --geom '{"type":"Polygon","coordinates":[[[0,0],[1,0],[1,1]]]}'
planet.exceptions.GeoJSONError: Each linear ring must contain at least 4 positions
> planet subscriptions request-catalog --item-types PSScene --asset-types ortho_analytic_4b --geometry nofile.json --start-time 2022-01-01
planet.exceptions.FeatureError: Expected scheme pl:features
> planet subscriptions request-catalog --item-types PSScene --asset-types ortho_analytic_4b --geometry '' --start-time 2022-01-01
TypeError: 'NoneType' object is not subscriptable
> planet data filter --geom nofile.json
Error: Invalid value for '--geom': File not found.
Environment Information
- Operation System Information: macOS-27.0.1-arm64-arm-64bit
- Python version: 3.12.15 (main, Oct 9 2026, 15:10:57) [Clang 22.1.3 ]
- Planet package version: planet, version 3.7.0 (PyPI wheel, and main at a6c66cb, which is the 3.7.0 tag). click 8.5.0.
Installation Method
- pip wheel (
uv pip install planet) and from source (pip install -e .)
Found and reproduced with an AI coding assistant, then checked by me.
- Vorherrschende Sprache
- Python
- Sterne
- 300
- Forks
- 100
- Ø Merge
- 6 T. 18 Std.
- Gemergte PRs (30 T.)
- 1
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus planetlabs/planet-client-python
-
DataClient.wait_asset raises "Maximum number of attempts reached" when the last poll returns an active assetEvtl. vergeben @sebxt hat das vor 18 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
planetlabs/planet-client-python#1232 ·
-
better-testing
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
planetlabs/planet-client-python#1110 ·
-
Broken examples in order_request and subscription_request docstrings, async SDK guide and CLI tipsOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 35/100
planetlabs/planet-client-python#1231 ·
-
FeaturesClient list_items does not support filteringEvtl. vergeben @steps-re hat das vor 121 Tagen übernommen. Offenproposal
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 65/100
planetlabs/planet-client-python#1221 ·
-
FeaturesClient does not implement Update FeatureEvtl. vergeben @tbarsballe hat das vor 150 Tagen übernommen. Offenproposal
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 57/100
planetlabs/planet-client-python#1214 ·
Alle Issues in planetlabs/planet-client-python
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
didi/helixharness#18 ·
-
request-theme
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
LizardByte/ThemerrDB#9883 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
NousResearch/hermes-agent#149885 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Set cache_ok = True on GUID TypeDecorator to enable SQLAlchemy query cachingEvtl. vergeben @patelshivani2283-lab hat das heute übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 91/100
fedora-infra/anitya#2157 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
Project-MONAI/MONAI#9258 ·
Maintainer antworten meist innerhalb von 3 Tagen