Repository: uber-go/dig
Pull request #310 (2022-01-03 23:55:45)

scope: Use an empty name for root
In the original discussions for Scope, we said that the root scope
(`Container`) will have an empty name, not "container".

PR #305 introduced Scope with the default name "container".
Proposing this as a resolution to that pending discussion.


codecov[bot]: # [Codecov](https://codecov.io/gh/uber-go/dig/pull/310?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go) Report
> Merging [#310](https://codecov.io/gh/uber-go/dig/pull/310?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go) (ccc076b) into [master](https://codecov.io/gh/uber-go/dig/commit/97f49cac32d50bf1ab8afacbe5aff628aa0994e1?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go) (97f49ca) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/uber-go/dig/pull/310/graphs/tree.svg?width=650&height=150&src=pr&token=ARuH7Frwgw&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go)](https://codecov.io/gh/uber-go/dig/pull/310?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go)

```diff
@@           Coverage Diff           @@
##           master     #310   +/-   ##
=======================================
  Coverage   98.46%   98.46%           
=======================================
  Files          19       19           
  Lines        1234     1234           
=======================================
  Hits         1215     1215           
  Misses         11       11           
  Partials        8        8           
```


| [Impacted Files](https://codecov.io/gh/uber-go/dig/pull/310?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go) | Coverage Δ | |
|---|---|---|
| [scope.go](https://codecov.io/gh/uber-go/dig/pull/310/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-c2NvcGUuZ28=) | `98.70% <ø> (-0.02%)` | :arrow_down: |
| [cycle\_error.go](https://codecov.io/gh/uber-go/dig/pull/310/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-Y3ljbGVfZXJyb3IuZ28=) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/uber-go/dig/pull/310?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/uber-go/dig/pull/310?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go). Last update [97f49ca...ccc076b](https://codecov.io/gh/uber-go/dig/pull/310?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go).


Patch:
diff --git a/cycle_error.go b/cycle_error.go
index 7d81d84..03b9434 100644
--- a/cycle_error.go
+++ b/cycle_error.go
@@ -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 ")
diff --git a/scope.go b/scope.go
index 108ab50..8dcdb7d 100644
--- a/scope.go
+++ b/scope.go
@@ -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),


Test patch:
diff --git a/dig_test.go b/dig_test.go
index 2e3dd8d..92cd81f 100644
--- a/dig_test.go
+++ b/dig_test.go
@@ -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.")
 	})