Skip to content

Commit 0b6768d

Browse files
committed
v2: prettify petablint output
Previously, the raw ValidationError tracebacks where shown, which is not what a user wants to see. Related to #369.
1 parent ef79523 commit 0b6768d

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

petab/petablint.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
import sys
88

9+
import pydantic
910
from colorama import Fore
1011
from colorama import init as init_colorama
1112
from jsonschema.exceptions import ValidationError as SchemaValidationError
@@ -179,12 +180,22 @@ def main():
179180
case 2:
180181
from petab.v2.lint import lint_problem
181182

182-
validation_issues = lint_problem(args.yaml_file_name)
183-
if validation_issues:
184-
validation_issues.log(logger=logger)
183+
try:
184+
validation_issues = lint_problem(args.yaml_file_name)
185+
if validation_issues:
186+
# Handle petab.v2.lint.ValidationTask issues
187+
validation_issues.log(logger=logger)
188+
sys.exit(1)
189+
logger.info("PEtab format check completed successfully.")
190+
sys.exit(0)
191+
except pydantic.ValidationError as e:
192+
# Handle Pydantic validation errors
193+
for err in e.errors():
194+
loc = ", ".join(str(loc) for loc in err["loc"])
195+
msg = err["msg"]
196+
logger.error(f"Error in field(s) `{loc}`: {msg}")
185197
sys.exit(1)
186-
logger.info("PEtab format check completed successfully.")
187-
sys.exit(0)
198+
188199
case _:
189200
logger.error(
190201
"The provided PEtab files are of unsupported version "

0 commit comments

Comments
 (0)