Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: surface original error when raising verification error #1192

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions xdsl/ir/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,9 @@ def verify(self, verify_nested_ops: bool = True) -> None:
try:
self.verify_()
except VerifyException as err:
self.emit_error("Operation does not verify: " + str(err))
self.emit_error(
"Operation does not verify: " + str(err), underlying_error=err
)

def verify_(self) -> None:
pass
Expand Down Expand Up @@ -974,14 +976,17 @@ def is_structurally_equivalent(
return True

def emit_error(
self, message: str, exception_type: type[Exception] = VerifyException
self,
message: str,
exception_type: type[Exception] = VerifyException,
underlying_error: Exception | None = None,
) -> NoReturn:
"""Emit an error with the given message."""
from xdsl.utils.diagnostic import Diagnostic

diagnostic = Diagnostic()
diagnostic.add_message(self, message)
diagnostic.raise_exception(message, self, exception_type)
diagnostic.raise_exception(message, self, exception_type, underlying_error)

def __eq__(self, other: object) -> bool:
return self is other
Expand Down
3 changes: 2 additions & 1 deletion xdsl/utils/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def raise_exception(
message: str,
ir: IRNode,
exception_type: type[Exception] = DiagnosticException,
underlying_error: Exception | None = None,
) -> NoReturn:
"""Raise an exception, that will also print all messages in the IR."""
from xdsl.printer import Printer
Expand All @@ -38,4 +39,4 @@ def raise_exception(
else:
assert "xDSL internal error: get_toplevel_object returned unknown construct"

raise exception_type(message + "\n\n" + f.getvalue())
raise exception_type(message + "\n\n" + f.getvalue()) from underlying_error