Skip to content

4.0: runtime scope errors should be ResolutionErrors #562

Closed

Description

@lesnik512

This was generated by AI during a pre-4.0 audit of main at 9cd88e7.

Observation

docs/providers/errors-and-exceptions.md:101 says "Catch ResolutionError for any resolution failure", but ScopeNotInitializedError, ScopeSkippedError and ContainerClosedError subclass ContainerError (modern_di/exceptions/container.py:50,69,102). So except ResolutionError misses root.resolve(RequestScoped) and a resolve from a closed container.

Related: InvalidScopeDependencyError (exceptions/registration.py:168) subclasses RegistrationError, a module documented as "while providers and groups are declared", but it is raised by validate() (dependency_graph.py:197), so except RegistrationError catches a validation finding.

Changing a base class after 4.0 changes which except clauses fire, so it is a 5.0 change later and cheap now.

Proposal

  • Re-parent the three runtime errors under ResolutionError (they already carry DependencyPathMixin). Decide whether ContainerError stays a second base for them or is reserved for construction-time errors (InvalidChildScopeError, MaxScopeReachedError, InvalidScopeTypeError).
  • Decide the family of InvalidScopeDependencyError (validation, not registration).
  • Update errors-and-exceptions.md and the migration guide.

Acceptance

  • except ResolutionError catches every error raised from resolve/resolve_provider, with a test per error type.
  • Hierarchy table in the docs matches the code; migration guide has an entry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestready-for-agentFully specified, ready for an AFK agent

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions