Skip to content

Commit

Permalink
feat: make some VCDReader exceptions unchained
Browse files Browse the repository at this point in the history
These parse-time exceptions stand on their own and do not need to be
chained with their precipitating ValueErrors.
  • Loading branch information
jpgrayson committed Nov 10, 2024
1 parent 3d1f78e commit 653cb81
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions vcd/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,9 @@ def _parse_token(s: _TokenizerState) -> Token:
real = float(bytes(real_digits))
except ValueError:
real_str = bytes(real_digits).decode("ascii")
raise VCDParseError(start, f"Expected real value, got: {real_str}")
raise VCDParseError(
start, f"Expected real value, got: {real_str}"
) from None

s.skip_ws()

Expand Down Expand Up @@ -594,7 +596,9 @@ def _parse_token(s: _TokenizerState) -> Token:
try:
scope_type = ScopeType(identifier)
except ValueError:
raise VCDParseError(s.loc, f"Invalid $scope type: {identifier}")
raise VCDParseError(
s.loc, f"Invalid $scope type: {identifier}"
) from None

s.skip_ws()

Expand All @@ -618,7 +622,7 @@ def _parse_token(s: _TokenizerState) -> Token:
s.loc,
f"Invalid $timescale magnitude: {mag_int}. "
f"Must be one of: {valid_magnitudes}.",
)
) from None

s.skip_ws()
unit_str = s.take_identifier()
Expand All @@ -630,7 +634,7 @@ def _parse_token(s: _TokenizerState) -> Token:
s.loc,
f"Invalid $timescale unit: {unit_str}. "
f"Must be one of: {valid_units}.",
)
) from None

s.take_end()

Expand All @@ -651,7 +655,7 @@ def _parse_token(s: _TokenizerState) -> Token:
raise VCDParseError(
s.loc,
f"Invalid $var type: {type_str}. Must be one of: {valid_types}",
)
) from None

s.skip_ws()
size = s.take_decimal()
Expand Down

0 comments on commit 653cb81

Please sign in to comment.