Skip to content

Commit

Permalink
Merge pull request #19 from lengstrom/main
Browse files Browse the repository at this point in the history
made ValidationError handling more verbose
  • Loading branch information
GuillaumeLeclerc authored Jun 29, 2022
2 parents b39083a + a598697 commit 53dbda2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion fastargs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ def __getitem__(self, path):
if value is None and not param.required:
return value

return param.validate(value)
try:
return param.validate(value)
except ValidationError as e:
print(f'Issue when typechecking argument psyh `{".".join(path)}`:')
raise e


def get(self):
Expand Down
2 changes: 2 additions & 0 deletions fastargs/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def __call__(self, *args, **kwargs):
path = ns + path
if alias in kwargs: # User overrode this argument
continue

value = config[path]

if value is not None:
filled_args[alias] = value

Expand Down
4 changes: 2 additions & 2 deletions fastargs/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def __init__(self, checker, desc='', default=None, required=False,
self.section = None

def __str__(self):

result = ""

if self.required:
Expand All @@ -37,5 +36,6 @@ def validate(self, value):
try:
return self.checker.check(value)
except Exception:
raise ValidationError()
msg = f'value `{value}` does not fit checker for `{self.checker.help()}`'
raise ValidationError(msg)

0 comments on commit 53dbda2

Please sign in to comment.