qiime2 / q2cli

Command line interface for QIIME 2
BSD 3-Clause "New" or "Revised" License
19 stars 24 forks source link

improve error message from `qiime tools replay-proveance` on invalid input file path #321

Open gregcaporaso opened 11 months ago

gregcaporaso commented 11 months ago

I got the following error message after passing a invalid file path (my input file didn't exist). This should produce a more concise error message, just focused around the FileNotFoundError.

$  qiime tools replay-provenance --in-fp cm99979-obs-features.qza --out-fp replay-reads.bash
Traceback (most recent call last):
  File "/masked-path/qiime2-shotgun-2023.9/bin/qiime", line 11, in <module>
    sys.exit(qiime())
  File "/masked-path/qiime2-shotgun-2023.9/lib/python3.8/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/masked-path/qiime2-shotgun-2023.9/lib/python3.8/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/masked-path/qiime2-shotgun-2023.9/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/masked-path/qiime2-shotgun-2023.9/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/masked-path/qiime2-shotgun-2023.9/lib/python3.8/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/masked-path/qiime2-shotgun-2023.9/lib/python3.8/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/masked-path/qiime2-shotgun-2023.9/lib/python3.8/site-packages/q2cli/builtin/tools.py", line 1018, in provenance_replay
    replay_provenance(
  File "/masked-path/qiime2-shotgun-2023.9/lib/python3.8/site-packages/qiime2/core/archive/provenance_lib/replay.py", line 286, in replay_provenance
    dag = ProvDAG(
  File "/masked-path/qiime2-shotgun-2023.9/lib/python3.8/site-packages/qiime2/core/archive/provenance_lib/parse.py", line 85, in __init__
    parser_results = parse_provenance(cfg, artifact_data)
  File "/masked-path/qiime2-shotgun-2023.9/lib/python3.8/site-packages/qiime2/core/archive/provenance_lib/parse.py", line 541, in parse_provenance
    parser = select_parser(payload)
  File "/masked-path/qiime2-shotgun-2023.9/lib/python3.8/site-packages/qiime2/core/archive/provenance_lib/parse.py", line 594, in select_parser
    raise UnparseableDataError(err_msg)
qiime2.core.archive.provenance_lib.parse.UnparseableDataError: Input data cm99979-obs-features.qza is not supported.
Parsers are available for the following data types: ['a path to a file (a string) or a file-like object', 'filepath to a directory containing .qza/.qzv archives', 'ProvDAG', 'None'].
The following errors were caught while trying to identify a parser that can_handle this input data:
<class 'FileNotFoundError'>[Errno 2] No such file or directory: 'cm99979-obs-features.qza'
<class 'ValueError'> in DirectoryParser: cm99979-obs-features.qza is not a valid directory.
<class 'TypeError'> in ProvDAGParser: cm99979-obs-features.qza is not a ProvDAG.
<class 'TypeError'> in EmptyParser: cm99979-obs-features.qza is not None.
colinvwood commented 10 months ago

Four different types of payloads are accepted as indicated by this line:

Parsers are available for the following data types: ['a path to a file (a string) or a file-like object', 'filepath to a directory containing .qza/.qzv archives', 'ProvDAG', 'None'].

Finding the proper parser is done by try/excepting each of them. We can't know that the FileNotFoundError is the most meaningful error.

gregcaporaso commented 9 months ago

Thanks for looking into @colinvwood. Could we perform specific checks to narrow it down, either instead of the try/except or as a result of an Exception being raised?