Skip to content

Commit

Permalink
🧹 Include mrn in ErrVariantCycleDetected. (#922)
Browse files Browse the repository at this point in the history
* 🧹 Include mrn in ErrVariantCycleDetected.

* Fix test
  • Loading branch information
preslavgerchev authored Nov 3, 2023
1 parent 84d011b commit 08a29aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions policy/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,9 @@ const (
VISITED
)

var ErrVariantCycleDetected = errors.New("variant cycle detected")
var ErrVariantCycleDetected = func(mrn string) error {
return fmt.Errorf("variant cycle in %s detected", mrn)
}

func detectVariantCycles(queries map[string]*explorer.Mquery) error {
statusMap := map[string]nodeVisitStatus{}
Expand All @@ -623,7 +625,7 @@ func detectVariantCyclesDFS(mrn string, statusMap map[string]nodeVisitStatus, qu
if s == VISITED {
return nil
} else if s == ACTIVE {
return ErrVariantCycleDetected
return ErrVariantCycleDetected(mrn)
}
statusMap[q.Mrn] = ACTIVE
for _, variant := range q.Variants {
Expand Down
4 changes: 2 additions & 2 deletions policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ queries:
pInitial := bundleInitial.Policies[0]
pInitial.InvalidateLocalChecksums()
_, err = bundleInitial.Compile(context.Background(), schema, nil)
require.Equal(t, policy.ErrVariantCycleDetected, err)
require.Equal(t, policy.ErrVariantCycleDetected("//local.cnspec.io/run/local-execution/queries/variant1"), err)
}

{
Expand Down Expand Up @@ -401,6 +401,6 @@ queries:
pInitial := bundleInitial.Policies[0]
pInitial.InvalidateLocalChecksums()
_, err = bundleInitial.Compile(context.Background(), schema, nil)
require.Equal(t, policy.ErrVariantCycleDetected, err)
require.Equal(t, policy.ErrVariantCycleDetected("//local.cnspec.io/run/local-execution/queries/variant1"), err)
}
}

0 comments on commit 08a29aa

Please sign in to comment.