diff --git a/augur/filter.py b/augur/filter.py index c850f3ed8..c29608cdf 100644 --- a/augur/filter.py +++ b/augur/filter.py @@ -1734,6 +1734,10 @@ def numeric_date(date): except (ValueError, isodate.ISO8601Error): pass + # This currently doesn't get exposed since argparse raises a SystemExit on invalid arguments. + # TODO: find a way to provide better errors for invalid dates. + raise ValueError(f"Unable to determine date from {date}.") + def calculate_sequences_per_group(target_max_value, counts_per_group, allow_probabilistic=True): """Calculate the number of sequences per group for a given maximum number of diff --git a/tests/test_filter.py b/tests/test_filter.py index 248c1706d..f2f087579 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -356,3 +356,19 @@ def test_filter_relative_dates(self, tmpdir, argparser, argparse_params, metadat with open(out_fn) as f: output_sorted = sorted(line.rstrip() for line in f) assert output_sorted == output_sorted_expected + + @freeze_time("2020-03-25") + @pytest.mark.parametrize( + "argparse_params", + [ + "--max-date 3000Y", + "--max-date invalid", + ], + ) + def test_filter_relative_dates_error(self, tmpdir, argparser, argparse_params): + """Test that invalid dates fail""" + out_fn = str(tmpdir / "filtered.txt") + meta_fn = write_metadata(tmpdir, (("strain","date"), + ("SEQ_1","2020-03-23"))) + with pytest.raises(SystemExit): + argparser(f'--metadata {meta_fn} --output-strains {out_fn} {argparse_params}')