-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Labels
enhancementNew feature or requestNew feature or request
Description
If you try to resolve a type that hasn't been added, an error with the entire service provider type is emitted as well as a cryptic message saying the trait bound is not satisfied
error[E0277]: the trait bound `ServiceProvider<EmptyServiceProvider, HCons<TransientFactoryContainer<HCons<ControllerB, HNil>, SchemaB, [closure@teloc/tests/add_transient.rs:41:32: 44:10]>, HCons<TransientContainer<SchemaA>, HCons<TransientContainer<ControllerB>, HNil>>>>: Resolver<'_, _, ControllerA, _>` is not satisfied
--> teloc/tests/add_transient.rs:45:37
|
45 | let schema: SchemaA = container.resolve();
| ^^^^^^^ the trait `Resolver<'_, _, ControllerA, _>` is not implemented for `ServiceProvider<EmptyServiceProvider, HCons<TransientFactoryContainer<HCons<ControllerB, HNil>, SchemaB, [closure@teloc/tests/add_transient.rs:41:32: 44:10]>, HCons<TransientContainer<SchemaA>, HCons<TransientContainer<ControllerB>, HNil>>>>`
|
= note: required because of the requirements on the impl of `GetDependencies<'_, HCons<ControllerA, HCons<ControllerB, HNil>>, HCons<(_, _), HCons<(&TransientContainer<ControllerB>, (teloc::index::SelfIndex<There<There<Here>>>, HNil, HNil)), HNil>>>` for `ServiceProvider<EmptyServiceProvider, HCons<TransientFactoryContainer<HCons<ControllerB, HNil>, SchemaB, [closure@teloc/tests/add_transient.rs:41:32: 44:10]>, HCons<TransientContainer<SchemaA>, HCons<TransientContainer<ControllerB>, HNil>>>>`
= note: required because of the requirements on the impl of `Resolver<'_, &TransientContainer<SchemaA>, SchemaA, (teloc::index::SelfIndex<There<Here>>, HCons<ControllerA, HCons<ControllerB, HNil>>, HCons<(_, _), HCons<(&TransientContainer<ControllerB>, (teloc::index::SelfIndex<There<There<Here>>>, HNil, HNil)), HNil>>)>` for `ServiceProvider<EmptyServiceProvider, HCons<TransientFactoryContainer<HCons<ControllerB, HNil>, SchemaB, [closure@teloc/tests/add_transient.rs:41:32: 44:10]>, HCons<TransientContainer<SchemaA>, HCons<TransientContainer<ControllerB>, HNil>>>>`
I'm not sure how this would actually be implemented, but adding a message to provide a recommended fix could be useful. In this example, the recommendation could be something like
No container added for type ContainerA. Add the type ContainerA as Transient so that SchemaA can be resolved.
Ideally, we could provide customized error messages so that if you are trying to resolve a reference, you can recommend different solutions (such as providing a singleton or instance container).
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request