improve parser exception handling
This commit is contained in:
parent
0bef9a1869
commit
6b0148241a
1 changed files with 9 additions and 4 deletions
|
@ -35,7 +35,12 @@ class DieParser:
|
||||||
"""
|
"""
|
||||||
Parses the die expression and returns the result.
|
Parses the die expression and returns the result.
|
||||||
"""
|
"""
|
||||||
clean_expression = "".join(expression.split())
|
try:
|
||||||
result = self._parser.parse(clean_expression, semantics=self._semantics)
|
clean_expression = "".join(expression.split())
|
||||||
logging.debug(f"rolling die for {expression} -> result={result}")
|
result = self._parser.parse(clean_expression, semantics=self._semantics)
|
||||||
return result
|
logging.debug(f"rolling die for {expression} -> result={result}")
|
||||||
|
return result
|
||||||
|
except tatsu.exceptions.FailedParse as e:
|
||||||
|
message = f"Failed to roll {expression}: {e.message}"
|
||||||
|
self._logger.error(message)
|
||||||
|
raise ValueError(message) from e
|
||||||
|
|
Loading…
Reference in a new issue