Skip to content

Commit

Permalink
scope: Use an empty name for root (#310)
Browse files Browse the repository at this point in the history
Root scope should have an empty name, not a string like "container".
Cycle error will skip the `[scope "foo"]` for the root container.
  • Loading branch information
abhinav authored Jan 4, 2022
1 parent 97f49ca commit 5e5a20d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cycle_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func (e errCycleDetected) Error() string {
//
b := new(bytes.Buffer)

fmt.Fprintf(b, "[scope %q]\n", e.scope.name)
if name := e.scope.name; len(name) > 0 {
fmt.Fprintf(b, "[scope %q]\n", name)
}
for i, entry := range e.Path {
if i > 0 {
b.WriteString("\n\tdepends on ")
Expand Down
1 change: 1 addition & 0 deletions dig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,7 @@ func testProvideCycleFails(t *testing.T, dryRun bool) {
`depends on func\(\*dig.A\) \*dig.B provided by "go.uber.org/dig".testProvideCycleFails.\S+ \(\S+\)`,
`depends on func\(\*dig.C\) \*dig.A provided by "go.uber.org/dig".testProvideCycleFails.\S+ \(\S+\)`,
)
assert.NotContains(t, err.Error(), "[scope")
assert.Error(t, c.Invoke(func(c *C) {}), "expected invoking a function that uses a type that failed to provide to fail.")
})

Expand Down
1 change: 0 additions & 1 deletion scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ type Scope struct {

func newScope() *Scope {
s := &Scope{
name: "container",
providers: make(map[key][]*constructorNode),
values: make(map[key]reflect.Value),
groups: make(map[key][]reflect.Value),
Expand Down

0 comments on commit 5e5a20d

Please sign in to comment.