Skip to content

Commit

Permalink
document exception sources better
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-c committed Sep 13, 2021
1 parent f91d883 commit f1f465c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 7 additions & 7 deletions schema_salad/avro/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ def __init__(
type_schema = make_avsc_object(atype, names)
except Exception as e:
raise SchemaParseException(
f'Type property "{atype}" not a valid Avro schema: {e}'
)
f'Type property "{atype}" not a valid Avro schema.'
) from e
self.set_prop("type", type_schema)
self.set_prop("name", name)
self.type = type_schema
Expand Down Expand Up @@ -409,9 +409,9 @@ def __init__(
items_schema = make_avsc_object(items, names)
except Exception as err:
raise SchemaParseException(
"Items schema ({}) not a valid Avro schema: {} (known "
"names: {})".format(items, err, list(names.names.keys()))
)
f"Items schema ({items}) not a valid Avro schema: (known "
f"names: {list(names.names.keys())})."
) from err

self.set_prop("items", items_schema)

Expand Down Expand Up @@ -451,8 +451,8 @@ def __init__(
new_schema = make_avsc_object(schema, names)
except Exception as err:
raise SchemaParseException(
f"Union item must be a valid Avro schema: {err}. {schema}"
)
f"Union item must be a valid Avro schema: {schema}"
) from err
# check the new schema
if (
new_schema.type in VALID_TYPES
Expand Down
6 changes: 5 additions & 1 deletion schema_salad/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def validate_ex(
# type: (...) -> bool
"""Determine if a python datum is an instance of a schema."""

debug = _logger.isEnabledFor(logging.DEBUG)
if not identifiers:
identifiers = []

Expand Down Expand Up @@ -228,7 +229,10 @@ def validate_ex(
return False
except ValidationException as v:
if raise_ex:
raise ValidationException("item is invalid because", sl, [v])
source = v if debug else None
raise ValidationException(
"item is invalid because", sl, [v]
) from source
return False
return True
else:
Expand Down

0 comments on commit f1f465c

Please sign in to comment.