Skip to content

Commit

Permalink
Merge pull request #1646: index: Allow FileNotFoundError to be handle…
Browse files Browse the repository at this point in the history
…d at the top level
  • Loading branch information
victorlin authored Sep 30, 2024
2 parents bf05db8 + 296a6c6 commit 18fe343
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
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

0 comments on commit 18fe343

Please sign in to comment.