Skip to content

Replace RuntimeError raises with custom exception hierarchy#178

Merged
lesnik512 merged 1 commit intomainfrom
177-replace-runtimeerror-with-custom-exception-hierarchy
May 2, 2026
Merged

Replace RuntimeError raises with custom exception hierarchy#178
lesnik512 merged 1 commit intomainfrom
177-replace-runtimeerror-with-custom-exception-hierarchy

Conversation

@lesnik512
Copy link
Copy Markdown
Member

Introduces modern_di/exceptions.py with ModernDIError(RuntimeError) and a hierarchy keyed to the existing message templates: ContainerError, ResolutionError, RegistrationError, FinalizerError, GroupInstantiationError. Each subclass carries structured fields so callers can branch on type and introspect details instead of matching on RuntimeError message strings.

Inheriting from RuntimeError preserves backwards compatibility for anyone catching the broad type today. Tests updated to assert the typed exceptions and verify the structured fields.

Closes #177

Introduces modern_di/exceptions.py with ModernDIError(RuntimeError) and a
hierarchy keyed to the existing message templates: ContainerError,
ResolutionError, RegistrationError, FinalizerError, GroupInstantiationError.
Each subclass carries structured fields so callers can branch on type and
introspect details instead of matching on RuntimeError message strings.

Inheriting from RuntimeError preserves backwards compatibility for anyone
catching the broad type today. Tests updated to assert the typed exceptions
and verify the structured fields.

Closes #177

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@lesnik512 lesnik512 self-assigned this May 2, 2026
@lesnik512 lesnik512 linked an issue May 2, 2026 that may be closed by this pull request
@lesnik512 lesnik512 merged commit 6fd7b4d into main May 2, 2026
7 checks passed
@lesnik512 lesnik512 deleted the 177-replace-runtimeerror-with-custom-exception-hierarchy branch May 2, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace RuntimeError with custom exception hierarchy

1 participant