Skip to content

Commit

Permalink
Include call location in error (#1)
Browse files Browse the repository at this point in the history
The error "no provider for type X" is often hard to debug.
This adds a call location to the error so we'll know where to start looking.
  • Loading branch information
swami-m authored Nov 22, 2019
1 parent 718e1fd commit e2107f4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"fmt"
"log"
"reflect"
"runtime"
"strings"

yaml "gopkg.in/yaml.v2"
Expand Down Expand Up @@ -197,7 +198,8 @@ func (c Config) Instance(ptr interface{}) error {
}
inst := c.instances[typ]
if inst == nil {
return fmt.Errorf("no provider for type %s", vptr.Type().Elem())
_, file, line, _ := runtime.Caller(1)
return fmt.Errorf("no provider for type %s (%s:%d)", vptr.Type().Elem(), file, line)
}
value := inst.Value()
// If we get an instance, it's guaranteed to have well-formed dependencies.
Expand Down

0 comments on commit e2107f4

Please sign in to comment.