adriangb / di

Pythonic dependency injection
https://www.adriangb.com/di/
MIT License
303 stars 13 forks source link

feat: better errors #67

Closed adriangb closed 2 years ago

adriangb commented 2 years ago

The errors that di currently emits are terrible. The main reason for this is that solving and execution flatten the execution graph (by topologically sorting it). So when you get an error you have no idea what called what.

I propose that during solving we keep track of the "path" to each dependency so that we can pretty format it into error messages (using rich?) and also include it in the error object for programatic access.

  1. During solving if there is a scope conflict, unwireable dependency, etc.
  2. We can pass the "path" to each dependency into the Task object. It will catch any exceptions from calling the dependency and do a raise from including this info.