Skip to content

Include dependency path in resolution error messages #170

@lesnik512

Description

@lesnik512

Problem

When a dependency can't be resolved, the error message is a flat string with no context about the resolution chain:

Argument db of type <class 'Database'> cannot be resolved. Trying to build dependency <class 'MyService'>.

For deep dependency graphs this makes it hard to understand where in the chain the failure occurred.

Proposed Solution

During recursive resolution in _compile_kwargs, catch resolution errors and re-raise with path context. Accumulate the dependency chain so the top-level error shows the full path from the initially requested type down to the missing dependency. Include scope at each level.

Example output:

Cannot resolve dependency chain:
  APP   MyService
  APP   └─> Repository
  APP       └─> Database  (not registered)

Impact

Dramatically easier debugging, especially for deep dependency graphs.

Complexity

Medium — touches factory.py error handling in _compile_kwargs.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions