Skip to content

Commit

Permalink
cycle error: Use [scope "foo"] (#309)
Browse files Browse the repository at this point in the history
Instead of always printing "In scope foo" print `[scope "foo"]`.
  • Loading branch information
abhinav authored Jan 3, 2022
1 parent c1350a7 commit 97f49ca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cycle_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ 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)
// depends on func(*bar) *foo provided by "path/to/package".NewFoo (path/to/file.go:42)
//
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 ")
Expand Down
6 changes: 3 additions & 3 deletions scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 97f49ca

Please sign in to comment.