Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index: Allow FileNotFoundError to be handled at the top level #1646

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## __NEXT__

### Bug Fixes

* index: Previously specifying a directory that does not exist in the path to `--output` would result in an incorrect error stating that the input file does not exist. It now shows the correct path responsible for the error. [#1644][] (@victorlin)

[#1644]: https://github.com/nextstrain/augur/issues/1644

## 26.0.0 (17 September 2024)

Expand Down
15 changes: 5 additions & 10 deletions augur/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""

from itertools import combinations
import sys
import csv

from .io.file import open_file
Expand Down Expand Up @@ -209,15 +208,11 @@ def run(args):
("?" and "-"), and other invalid characters in a set of sequences and write
the composition as a data frame to the given sequence index path.
'''
try:
if is_vcf(args.sequences):
num_of_seqs = index_vcf(args.sequences, args.output)
tot_length = None
else:
num_of_seqs, tot_length = index_sequences(args.sequences, args.output)
except FileNotFoundError:
print(f"ERROR: Could not open sequences file '{args.sequences}'.", file=sys.stderr)
return 1
if is_vcf(args.sequences):
num_of_seqs = index_vcf(args.sequences, args.output)
tot_length = None
else:
num_of_seqs, tot_length = index_sequences(args.sequences, args.output)

if args.verbose:
if tot_length:
Expand Down
13 changes: 11 additions & 2 deletions tests/functional/index.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ This should fail.
$ ${AUGUR} index \
> --sequences index/missing_sequences.fasta \
> --output "$TMP/sequence_index.tsv"
ERROR: Could not open sequences file 'index/missing_sequences.fasta'.
[1]
ERROR: No such file or directory: 'index/missing_sequences.fasta'
[2]

Try writing output to a directory that does not exist.
This should fail.

$ ${AUGUR} index \
> --sequences index/sequences.fasta \
> --output "results/sequence_index.tsv"
ERROR: No such file or directory: 'results/sequence_index.tsv'
[2]

$ popd > /dev/null
Loading