Skip to content

Commit 1a9cc7f

Browse files
committed
Validation mode warn no longer exits code 2
The help message for `--validation-mode` is very specific: > 'error' mode causes a non-zero exit status if any validation checks > failed, while 'warn' does not. In the actual implementation however we would print an error and exit with code 2 for any validation check _except_ the augur version check. Now, for `ValidationMode.WARN` we catch these errors and turn them into warnings such that augur can exit code 0 as specified.
1 parent af2abfe commit 1a9cc7f

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

augur/util_support/node_data_file.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -63,49 +63,49 @@ def validate(self):
6363
if self.validation_mode is ValidationMode.SKIP:
6464
return # don't perform validation (i.e. skip it)
6565

66-
if self.annotations:
67-
try:
68-
validate_json(
69-
self.annotations,
70-
load_json_schema("schema-annotations.json"),
71-
self.fname,
66+
try:
67+
if self.annotations:
68+
try:
69+
validate_json(
70+
self.annotations,
71+
load_json_schema("schema-annotations.json"),
72+
self.fname,
73+
)
74+
except ValidateError as err:
75+
raise AugurError(
76+
f"{self.fname} contains an `annotations` attribute of an invalid JSON format. Was it "
77+
"produced by different version of augur the one you are currently using "
78+
f" ({__version__})? Please check the program that produced that JSON file."
79+
) from err
80+
81+
if not isinstance(self.nodes, dict):
82+
raise AugurError(
83+
f"`nodes` value in {self.fname} is not a dictionary. Please check the formatting of this JSON!"
7284
)
73-
except ValidateError as err:
85+
86+
if not isinstance(self.branches, dict):
7487
raise AugurError(
75-
f"{self.fname} contains an `annotations` attribute of an invalid JSON format. Was it "
76-
"produced by different version of augur the one you are currently using "
77-
f" ({__version__})? Please check the program that produced that JSON file."
78-
) from err
79-
80-
if not isinstance(self.nodes, dict):
81-
raise AugurError(
82-
f"`nodes` value in {self.fname} is not a dictionary. Please check the formatting of this JSON!"
83-
)
84-
85-
if not isinstance(self.branches, dict):
86-
raise AugurError(
87-
f"`branches` value in {self.fname} is not a dictionary. Please check the formatting of this JSON!"
88-
)
89-
90-
if not self.nodes and not self.branches:
91-
print_err(
92-
f"WARNING: {self.fname} has empty or nonexistent `nodes` and `branches`. Please check the formatting of this JSON!"
93-
)
94-
95-
if self.is_generated_by_incompatible_augur:
96-
msg = (
97-
f"Augur version incompatibility detected: the JSON {self.fname} was generated by "
98-
f"{self.generated_by}, which is incompatible with the current augur version "
99-
f"({__version__}). We suggest you rerun the pipeline using the current version of "
100-
"augur."
101-
)
102-
if self.validation_mode is ValidationMode.ERROR:
88+
f"`branches` value in {self.fname} is not a dictionary. Please check the formatting of this JSON!"
89+
)
90+
91+
if not self.nodes and not self.branches:
92+
print_err(
93+
f"WARNING: {self.fname} has empty or nonexistent `nodes` and `branches`. Please check the formatting of this JSON!"
94+
)
95+
96+
if self.is_generated_by_incompatible_augur:
97+
msg = (
98+
f"Augur version incompatibility detected: the JSON {self.fname} was generated by "
99+
f"{self.generated_by}, which is incompatible with the current augur version "
100+
f"({__version__}). We suggest you rerun the pipeline using the current version of "
101+
"augur."
102+
)
103103
raise AugurError(msg)
104-
elif self.validation_mode is ValidationMode.WARN:
105-
print_err(f"WARNING: {msg}")
104+
except AugurError as e:
105+
if self.validation_mode is ValidationMode.WARN:
106+
print_err(f"WARNING: {e.args[0]}")
106107
else:
107-
raise ValueError(f"unknown validation mode: {self.validation_mode!r}")
108-
108+
raise e
109109

110110

111111
class NodeDataObject(NodeDataFile):

0 commit comments

Comments
 (0)