SETI / rms-pds4indextools

PDS4 index tools Python module
Apache License 2.0
0 stars 0 forks source link

Unknown sort key causes crash #22

Closed rfrenchseti closed 1 month ago

rfrenchseti commented 1 month ago

In pds4_create_xml_index, if the --sort-by option is specified with an unknown column name, an error is generated such as:

Traceback (most recent call last):
  File "/seti/all_repos/rms-pds4indextools/pds4indextools/pds4_create_xml_index.py", line 1529, in <module>
    main()
  File "/seti/all_repos/rms-pds4indextools/pds4indextools/pds4_create_xml_index.py", line 1368, in main
    write_results_to_csv(all_results, args, output_csv_path)
  File "/seti/all_repos/rms-pds4indextools/pds4indextools/pds4_create_xml_index.py", line 718, in write_results_to_csv
    df.sort_values(by=sort_values, inplace=True)
  File "/seti/all_repos/rms-pds4indextools/venv/lib/python3.12/site-packages/pandas/core/frame.py", line 7189, in sort_values
    k = self._get_label_or_level_values(by[0], axis=axis)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/seti/all_repos/rms-pds4indextools/venv/lib/python3.12/site-packages/pandas/core/generic.py", line 1911, in _get_label_or_level_values
    raise KeyError(key)
KeyError: 'is_instrument_host'

This is unfriendly to the user. Instead an error message such as:

Unknown sort key "is_instrument_host". For a list of available sort keys, use the --output-headers-file option.

would be preferable.