Skip to content

Commit 2be4f7d

Browse files
author
Charlie Egan
committed
store: Improve conflicting root error message
Fixes #7806 ```sh $ opa eval -b b1.tar.gz -b b2.tar.gz data; go run main.go eval -b b1.tar.gz -b b2.tar.gz data { "errors": [ { "message": "detected overlapping roots in bundle manifest with: [b1.tar.gz b2.tar.gz]" } ] } { "errors": [ { "message": "bundles b2.tar.gz, b1.tar.gz have overlapping roots and cannot be activated simultaneously because bundles b1.tar.gz specify empty root paths ('') which overlap with any other bundle root" } ] } ``` Signed-off-by: Charlie Egan <charlie@styra.com>
1 parent f5f00a9 commit 2be4f7d

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

v1/bundle/store.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,10 +1104,29 @@ func hasRootsOverlap(ctx context.Context, store storage.Store, txn storage.Trans
11041104

11051105
if len(collisions) > 0 {
11061106
var bundleNames []string
1107+
var bundlesWithEmptyRoots []string
1108+
11071109
for name := range collisions {
11081110
bundleNames = append(bundleNames, name)
1111+
1112+
bundle, ok := bundles[name]
1113+
if !ok || bundle.Manifest.Roots == nil {
1114+
continue
1115+
}
1116+
1117+
for _, root := range *bundle.Manifest.Roots {
1118+
if root == "" {
1119+
bundlesWithEmptyRoots = append(bundlesWithEmptyRoots, name)
1120+
break
1121+
}
1122+
}
11091123
}
1110-
return fmt.Errorf("detected overlapping roots in bundle manifest with: %s", bundleNames)
1124+
1125+
if len(bundlesWithEmptyRoots) > 0 {
1126+
return fmt.Errorf("bundles %s have overlapping roots and cannot be activated simultaneously because bundles %s specify empty root paths ('') which overlap with any other bundle root", strings.Join(bundleNames, ", "), strings.Join(bundlesWithEmptyRoots, ", "))
1127+
}
1128+
1129+
return fmt.Errorf("detected overlapping roots in bundle manifest with: %s", strings.Join(bundleNames, ", "))
11111130
}
11121131
return nil
11131132
}

v1/bundle/store_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6668,6 +6668,18 @@ func TestHasRootsOverlap(t *testing.T) {
66686668
bundleRoots: map[string]*[]string{"bundle2": {"c", "a"}, "bundle3": {"a"}},
66696669
overlaps: true,
66706670
},
6671+
{
6672+
note: "overlap with empty root bundle - bundle without manifest",
6673+
storeRoots: map[string]*[]string{"bundle1": {"a", "b"}},
6674+
bundleRoots: map[string]*[]string{"bundle2": {""}},
6675+
overlaps: true,
6676+
},
6677+
{
6678+
note: "overlap between multiple empty root bundles - bundles without manifests",
6679+
storeRoots: map[string]*[]string{},
6680+
bundleRoots: map[string]*[]string{"bundle1": {""}, "bundle2": {""}},
6681+
overlaps: true,
6682+
},
66716683
}
66726684

66736685
for _, tc := range cases {
@@ -6694,7 +6706,7 @@ func TestHasRootsOverlap(t *testing.T) {
66946706
err := hasRootsOverlap(ctx, mockStore, txn, bundles)
66956707
if !tc.overlaps && err != nil {
66966708
t.Fatalf("unepected error: %s", err)
6697-
} else if tc.overlaps && (err == nil || !strings.Contains(err.Error(), "detected overlapping roots in bundle manifest")) {
6709+
} else if tc.overlaps && (err == nil || (!strings.Contains(err.Error(), "detected overlapping roots in bundle manifest") && !strings.Contains(err.Error(), "have overlapping roots and cannot be activated simultaneously"))) {
66986710
t.Fatalf("expected overlapping roots error, got: %s", err)
66996711
}
67006712

0 commit comments

Comments
 (0)