Skip to content

Commit

Permalink
Print helpful error when metadata has invalid id
Browse files Browse the repository at this point in the history
Adds a functional test for how we'd like augur export v2 to behave when
the user provides metadata without a valid id and then updates the
try/except block in export_v2 to catch and print the error from
`read_metadata` when it occurs.

While we're at it, this commit also prints the error for missing
metadata file to stderr instead of stdout.
  • Loading branch information
huddlej committed May 4, 2022
1 parent 2fd09e0 commit 45df6bd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion augur/export_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,8 +999,11 @@ def run_v2(args):
if "strain" not in metadata_file[strain]:
metadata_file[strain]["strain"] = strain
except FileNotFoundError:
print(f"ERROR: meta data file ({args.metadata}) does not exist")
print(f"ERROR: meta data file ({args.metadata}) does not exist", file=sys.stderr)
sys.exit(2)
except Exception as error:
print(f"ERROR: {error}", file=sys.stderr)
sys.exit(1)
else:
metadata_file = {}

Expand Down
13 changes: 13 additions & 0 deletions tests/functional/export_v2.t
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,17 @@ In this case, the column is "name" (one of the default columns expected by Augur
{}
$ rm -f "$TMP/dataset1.json"

Run export with metadata that uses an invalid id column.
This should fail with a helpful error message.

$ ${AUGUR} export v2 \
> --tree export_v2/tree.nwk \
> --metadata export_v2/dataset1_metadata_without_valid_id.tsv \
> --node-data export_v2/div_node-data.json export_v2/location_node-data.json \
> --auspice-config export_v2/auspice_config1.json \
> --maintainers "Nextstrain Team" \
> --output "$TMP/dataset1.json" > /dev/null
ERROR: None of the possible id columns (('strain', 'name')) were found in the metadata's columns ('invalid_id', 'div', 'mutation_length')
[1]

$ popd > /dev/null
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
invalid_id div mutation_length
tipA 1 1
tipB 3 1
tipC 3 1
tipD 8 3
tipE 9 4
tipF 6 1

0 comments on commit 45df6bd

Please sign in to comment.