From 50198237f7bd3290acf035ca29f06c9aa06d8b46 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:47:06 -0700 Subject: [PATCH 1/2] Allow FileNotFoundError to be handled at the top level The removed error handling is flawed: it assumes that FileNotFoundError can only come from a missing input file (--sequences). The reality is that FileNotFoundError can also come from a missing output directory (--output). The top-level exception handler parses the filepath from the error directly, which is accurate. --- augur/index.py | 15 +++++---------- tests/functional/index.t | 13 +++++++++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/augur/index.py b/augur/index.py index 883cefd37..dfa94f7c6 100644 --- a/augur/index.py +++ b/augur/index.py @@ -2,7 +2,6 @@ """ from itertools import combinations -import sys import csv from .io.file import open_file @@ -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: diff --git a/tests/functional/index.t b/tests/functional/index.t index e0318beb9..df417c6fc 100644 --- a/tests/functional/index.t +++ b/tests/functional/index.t @@ -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 From 296a6c6ddb046ae8d27d1fbefedaa7c8eeaf0f4c Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:55:45 -0700 Subject: [PATCH 2/2] Update changelog --- CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 19ef09d3a..5e568a711 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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)