wire: improve error for a provider set with a binding but no corresponding provider (#126)
Fixes #113
This commit is contained in:
committed by
Ross Light
parent
b869afc095
commit
d810929d49
@@ -353,9 +353,11 @@ func buildProviderMap(fset *token.FileSet, hasher typeutil.Hasher, set *Provider
|
||||
}
|
||||
concrete := providerMap.At(b.Provided)
|
||||
if concrete == nil {
|
||||
pos := fset.Position(b.Pos)
|
||||
typ := types.TypeString(b.Provided, nil)
|
||||
ec.add(notePosition(pos, fmt.Errorf("no binding for %s", typ)))
|
||||
setName := set.VarName
|
||||
if setName == "" {
|
||||
setName = "provider set"
|
||||
}
|
||||
ec.add(notePosition(fset.Position(b.Pos), fmt.Errorf("wire.Bind of concrete type %q to interface %q, but %s does not include a provider for %q", b.Provided, b.Iface, setName, b.Provided)))
|
||||
continue
|
||||
}
|
||||
providerMap.Set(b.Iface, concrete)
|
||||
@@ -438,12 +440,10 @@ func verifyAcyclic(providerMap *typeutil.Map, hasher typeutil.Hasher) []error {
|
||||
// for the same output type.
|
||||
func bindingConflictError(fset *token.FileSet, typ types.Type, set *ProviderSet, cur, prev *providerSetSrc) error {
|
||||
sb := new(strings.Builder)
|
||||
if set.VarName == "" {
|
||||
fmt.Fprintf(sb, "wire.Build")
|
||||
} else {
|
||||
fmt.Fprintf(sb, set.VarName)
|
||||
if set.VarName != "" {
|
||||
fmt.Fprintf(sb, "%s has ", set.VarName)
|
||||
}
|
||||
fmt.Fprintf(sb, " has multiple bindings for %s\n", types.TypeString(typ, nil))
|
||||
fmt.Fprintf(sb, "multiple bindings for %s\n", types.TypeString(typ, nil))
|
||||
fmt.Fprintf(sb, "current:\n<- %s\n", strings.Join(cur.trace(fset, typ), "\n<- "))
|
||||
fmt.Fprintf(sb, "previous:\n<- %s", strings.Join(prev.trace(fset, typ), "\n<- "))
|
||||
return notePosition(fset.Position(set.Pos), errors.New(sb.String()))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
example.com/foo/wire.go:x:y: wire.Build has multiple bindings for example.com/foo.Foo
|
||||
example.com/foo/wire.go:x:y: multiple bindings for example.com/foo.Foo
|
||||
current:
|
||||
<- provider "provideFoo" (example.com/foo/foo.go:x:y)
|
||||
<- provider set "Set" (example.com/foo/foo.go:x:y)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
example.com/foo/wire.go:x:y: wire.Build has multiple bindings for string
|
||||
example.com/foo/wire.go:x:y: multiple bindings for string
|
||||
current:
|
||||
<- argument b to injector function inject (example.com/foo/wire.go:x:y)
|
||||
previous:
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
example.com/foo/wire.go:x:y: wire.Build has multiple bindings for example.com/foo.Foo
|
||||
example.com/foo/wire.go:x:y: multiple bindings for example.com/foo.Foo
|
||||
current:
|
||||
<- provider "provideFooAgain" (example.com/foo/foo.go:x:y)
|
||||
previous:
|
||||
<- provider "provideFoo" (example.com/foo/foo.go:x:y)
|
||||
|
||||
example.com/foo/wire.go:x:y: wire.Build has multiple bindings for example.com/foo.Foo
|
||||
example.com/foo/wire.go:x:y: multiple bindings for example.com/foo.Foo
|
||||
current:
|
||||
<- provider "provideFoo" (example.com/foo/foo.go:x:y)
|
||||
previous:
|
||||
<- provider "provideFoo" (example.com/foo/foo.go:x:y)
|
||||
<- provider set "Set" (example.com/foo/foo.go:x:y)
|
||||
|
||||
example.com/foo/wire.go:x:y: wire.Build has multiple bindings for example.com/foo.Foo
|
||||
example.com/foo/wire.go:x:y: multiple bindings for example.com/foo.Foo
|
||||
current:
|
||||
<- provider "provideFoo" (example.com/foo/foo.go:x:y)
|
||||
previous:
|
||||
@@ -28,13 +28,13 @@ previous:
|
||||
<- provider "provideFoo" (example.com/foo/foo.go:x:y)
|
||||
<- provider set "Set" (example.com/foo/foo.go:x:y)
|
||||
|
||||
example.com/foo/wire.go:x:y: wire.Build has multiple bindings for example.com/foo.Foo
|
||||
example.com/foo/wire.go:x:y: multiple bindings for example.com/foo.Foo
|
||||
current:
|
||||
<- wire.Value (example.com/foo/wire.go:x:y)
|
||||
previous:
|
||||
<- provider "provideFoo" (example.com/foo/foo.go:x:y)
|
||||
|
||||
example.com/foo/wire.go:x:y: wire.Build has multiple bindings for example.com/foo.Bar
|
||||
example.com/foo/wire.go:x:y: multiple bindings for example.com/foo.Bar
|
||||
current:
|
||||
<- wire.Bind (example.com/foo/wire.go:x:y)
|
||||
previous:
|
||||
|
||||
@@ -1 +1 @@
|
||||
example.com/foo/foo.go:x:y: no binding for *example.com/foo.foo
|
||||
example.com/foo/foo.go:x:y: wire.Bind of concrete type "*example.com/foo.foo" to interface "example.com/foo.fooer", but setB does not include a provider for "*example.com/foo.foo"
|
||||
@@ -276,7 +276,7 @@ func (g *gen) frame() []byte {
|
||||
if len(g.anonImports) > 0 {
|
||||
buf.WriteString("import (\n")
|
||||
anonImps := make([]string, 0, len(g.anonImports))
|
||||
for path, _ := range g.anonImports {
|
||||
for path := range g.anonImports {
|
||||
anonImps = append(anonImps, path)
|
||||
}
|
||||
sort.Strings(anonImps)
|
||||
|
||||
Reference in New Issue
Block a user