wire: add info from the dependency graph when a type is not provided

This commit is contained in:
Robert van Gent
2018-10-17 14:14:08 -07:00
committed by Ross Light
parent b84ad6154f
commit a8825fef58
5 changed files with 72 additions and 24 deletions

View File

@@ -122,6 +122,7 @@ func solve(fset *token.FileSet, out types.Type, given []types.Type, set *Provide
type frame struct {
t types.Type
from types.Type
up *frame
}
stk := []frame{{t: out}}
dfs:
@@ -135,12 +136,15 @@ dfs:
switch pv := set.For(curr.t); {
case pv.IsNil():
if curr.from == nil {
ec.add(fmt.Errorf("no provider found for %s (output of injector)", types.TypeString(curr.t, nil)))
ec.add(fmt.Errorf("no provider found for %s, output of injector", types.TypeString(curr.t, nil)))
index.Set(curr.t, errAbort)
continue
}
// TODO(light): Give name of provider.
ec.add(fmt.Errorf("no provider found for %s (required by provider of %s)", types.TypeString(curr.t, nil), types.TypeString(curr.from, nil)))
neededBy := []string{types.TypeString(curr.t, nil)}
for f := curr.up; f != nil; f = f.up {
neededBy = append(neededBy, fmt.Sprintf("%s in %s", types.TypeString(f.t, nil), set.srcMap.At(f.t).(*providerSetSrc).description(fset, f.t)))
}
ec.add(fmt.Errorf("no provider found for %s", strings.Join(neededBy, ", needed by ")))
index.Set(curr.t, errAbort)
continue
case pv.IsProvider():
@@ -151,7 +155,7 @@ dfs:
// Interface binding. Don't create a call ourselves.
i := index.At(concrete)
if i == nil {
stk = append(stk, curr, frame{t: concrete, from: curr.t})
stk = append(stk, curr, frame{t: concrete, from: curr.t, up: &curr})
continue
}
index.Set(curr.t, i)
@@ -169,7 +173,7 @@ dfs:
stk = append(stk, curr)
visitedArgs = false
}
stk = append(stk, frame{t: a.Type, from: curr.t})
stk = append(stk, frame{t: a.Type, from: curr.t, up: &curr})
}
}
if !visitedArgs {
@@ -208,7 +212,7 @@ dfs:
// Interface binding. Don't create a call ourselves.
i := index.At(v.Out)
if i == nil {
stk = append(stk, curr, frame{t: v.Out, from: curr.t})
stk = append(stk, curr, frame{t: v.Out, from: curr.t, up: &curr})
continue
}
index.Set(curr.t, i)