Repository: uber-go/dig
Pull request #309 (2022-01-03 23:53:00)

cycle error: Use [scope "foo"]
Instead of always printing "In scope foo" print `[scope "foo"]`.


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

[![Impacted file tree graph](https://codecov.io/gh/uber-go/dig/pull/309/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/309?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     #309   +/-   ##
=======================================
  Coverage   98.46%   98.46%           
=======================================
  Files          19       19           
  Lines        1235     1235           
=======================================
  Hits         1216     1216           
  Misses         11       11           
  Partials        8        8           
```


| [Impacted Files](https://codecov.io/gh/uber-go/dig/pull/309?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go) | Coverage Δ | |
|---|---|---|
| [cycle\_error.go](https://codecov.io/gh/uber-go/dig/pull/309/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/309?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/309?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go). Last update [f774a98...62d0c54](https://codecov.io/gh/uber-go/dig/pull/309?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 c1d41ab..7d81d84 100644
--- a/cycle_error.go
+++ b/cycle_error.go
@@ -40,6 +40,7 @@ type errCycleDetected struct {
 func (e errCycleDetected) Error() string {
 	// We get something like,
 	//
+	//   [scope "foo"]
 	//   func(*bar) *foo provided by "path/to/package".NewFoo (path/to/file.go:42)
 	//   	depends on func(*baz) *bar provided by "another/package".NewBar (somefile.go:1)
 	//   	depends on func(*foo) baz provided by "somepackage".NewBar (anotherfile.go:2)
@@ -47,7 +48,7 @@ func (e errCycleDetected) Error() string {
 	//
 	b := new(bytes.Buffer)
 
-	fmt.Fprintf(b, "In Scope %s: \n", e.scope.name)
+	fmt.Fprintf(b, "[scope %q]\n", e.scope.name)
 	for i, entry := range e.Path {
 		if i > 0 {
 			b.WriteString("\n\tdepends on ")
diff --git a/graph.go b/graph.go
index 6c8e7e1..e08f1f5 100644
--- a/graph.go
+++ b/graph.go
@@ -24,8 +24,6 @@ import "go.uber.org/dig/internal/graph"
 
 // graphNode is a single node in the dependency graph.
 type graphNode struct {
-	// The index of this node in the graphHolder's nodes.
-	Order   int
 	Wrapped interface{}
 }
 
@@ -83,7 +81,6 @@ func (gh *graphHolder) EdgesFrom(u int) []int {
 func (gh *graphHolder) NewNode(wrapped interface{}) int {
 	order := len(gh.nodes)
 	gh.nodes = append(gh.nodes, &graphNode{
-		Order:   order,
 		Wrapped: wrapped,
 	})
 	return order


Test patch:
diff --git a/scope_test.go b/scope_test.go
index cb3058c..fede567 100644
--- a/scope_test.go
+++ b/scope_test.go
@@ -162,7 +162,7 @@ func TestScopeFailures(t *testing.T) {
 
 			if fails {
 				assert.Error(t, err, "expected a cycle to be introduced in the child")
-				assert.Contains(t, err.Error(), "In Scope child")
+				assert.Contains(t, err.Error(), `[scope "child"]`)
 			} else {
 				assert.NoError(t, err)
 			}
@@ -177,7 +177,7 @@ func TestScopeFailures(t *testing.T) {
 			err := c.Provide(newC)
 			if fails {
 				assert.Error(t, err, "expected a cycle to be introduced in the child")
-				assert.Contains(t, err.Error(), "In Scope child")
+				assert.Contains(t, err.Error(), `[scope "child"]`)
 			} else {
 				assert.NoError(t, err)
 			}
@@ -240,7 +240,7 @@ func TestScopeFailures(t *testing.T) {
 		// C <- A made available to all Scopes with Export provide.
 		err := child1.Provide(newC, Export(true))
 		assert.Error(t, err, "expected a cycle to be introduced in child 2")
-		assert.Contains(t, err.Error(), "In Scope child 2")
+		assert.Contains(t, err.Error(), `[scope "child 2"]`)
 	})
 
 	t.Run("private provides do not propagate upstream", func(t *testing.T) {