From b096c2b8216c95d4f0c6a0d7bf023a0b0170cb4a Mon Sep 17 00:00:00 2001 From: Daniel Johnson Date: Wed, 12 Apr 2023 16:32:18 -0700 Subject: [PATCH] Adds descriptive error when failing to make concrete (#51) If using lazy loading and the call to a resolver when making a concrete fails, that error wasn't wrapped and caused confusion since we didn't know which abstraction we were attempting to satisfy. Wrapping error so we know that: a) Error occurred during resolve call. b) What abstraction we were trying to resolve. This should make it easier to debug these failures in lazy loading situations. --- container.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container.go b/container.go index b6dfe4d..d97ba2d 100644 --- a/container.go +++ b/container.go @@ -239,7 +239,7 @@ func (c Container) NamedResolve(abstraction interface{}, name string) error { reflect.ValueOf(abstraction).Elem().Set(reflect.ValueOf(instance)) return nil } else { - return err + return fmt.Errorf("container: encountered error while making concrete for: %s. Error encountered: %w", elem.String(), err) } }