Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/kirin/ir/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,11 @@ class DefiniteValidationError(ValidationError):
"""Indicates a definite violation that will occur at runtime."""

pass


class ValidationErrorGroup(BaseException):
"""Container for multiple validation errors (Python 3.10+ compatible)."""

def __init__(self, message: str, errors: list[ValidationError]) -> None:
super().__init__(message)
self.errors = errors
9 changes: 4 additions & 5 deletions src/kirin/validation/validationpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import field, dataclass

from kirin import ir
from kirin.ir.exception import ValidationError
from kirin.ir.exception import ValidationError, ValidationErrorGroup

T = TypeVar("T")

Expand Down Expand Up @@ -180,9 +180,8 @@ def raise_if_invalid(self):
"""Raise an exception if validation failed."""
if not self.is_valid:
exceptions = []
for pass_name, pass_errors in self.errors.items():
for err in pass_errors:
exceptions.append(err)
for _, pass_errors in self.errors.items():
exceptions.extend(pass_errors)

message = self._format_errors()
raise ExceptionGroup(message, exceptions)
raise ValidationErrorGroup(message, errors=exceptions)