mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
bundle: Add more details to manifest root errors
Signed-off-by: Patrick East <east.patrick@gmail.com>
This commit is contained in:
+2
-2
@@ -92,7 +92,7 @@ func (m *Manifest) validateAndInjectDefaults(b Bundle) error {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return fmt.Errorf("manifest roots do not permit '%v' in %v", module.Parsed.Package, module.Path)
|
||||
return fmt.Errorf("manifest roots %v do not permit '%v' in module '%v'", roots, module.Parsed.Package, module.Path)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ func (m *Manifest) validateAndInjectDefaults(b Bundle) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, fmt.Errorf("manifest roots do not permit data at path %v", path)
|
||||
return false, fmt.Errorf("manifest roots %v do not permit data at path '/%s' (hint: check bundle directory structure)", roots, path)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ func TestReadRootValidation(t *testing.T) {
|
||||
{"/.manifest", `{"revision": "abcd", "roots": []}`},
|
||||
{"/x.rego", `package foo`},
|
||||
},
|
||||
err: "manifest roots do not permit 'package foo' in /x.rego",
|
||||
err: "manifest roots [] do not permit 'package foo' in module '/x.rego'",
|
||||
},
|
||||
{
|
||||
note: "err: overlapped",
|
||||
@@ -158,7 +158,7 @@ func TestReadRootValidation(t *testing.T) {
|
||||
{"/a.rego", `package b.c`},
|
||||
{"/x.rego", `package c.e`},
|
||||
},
|
||||
err: "manifest roots do not permit 'package c.e' in /x.rego",
|
||||
err: "manifest roots [a b c/d] do not permit 'package c.e' in module '/x.rego'",
|
||||
},
|
||||
{
|
||||
note: "err: data outside scope",
|
||||
@@ -167,7 +167,7 @@ func TestReadRootValidation(t *testing.T) {
|
||||
{"/data.json", `{"a": 1}`},
|
||||
{"/c/e/data.json", `"bad bad bad"`},
|
||||
},
|
||||
err: "manifest roots do not permit data at path c/e",
|
||||
err: "manifest roots [a b c/d] do not permit data at path '/c/e'",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -161,6 +161,9 @@ func AsBundle(path string) (*bundle.Bundle, error) {
|
||||
|
||||
br := bundle.NewCustomReader(bundleLoader)
|
||||
b, err := br.Read()
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("bundle %s", path))
|
||||
}
|
||||
return &b, err
|
||||
}
|
||||
|
||||
@@ -335,7 +338,11 @@ func loadKnownTypes(path string, bs []byte) (interface{}, error) {
|
||||
return loadYAML(path, bs)
|
||||
default:
|
||||
if strings.HasSuffix(path, ".tar.gz") {
|
||||
return loadBundleFile(bs)
|
||||
r, err := loadBundleFile(bs)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("bundle %s", path))
|
||||
}
|
||||
return r, err
|
||||
}
|
||||
}
|
||||
return nil, unrecognizedFile(path)
|
||||
|
||||
+1
-1
@@ -1322,7 +1322,7 @@ func (r *Rego) loadBundles(ctx context.Context, txn storage.Transaction, m metri
|
||||
for _, path := range r.bundlePaths {
|
||||
bndl, err := loader.AsBundle(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading bundle path %s: %s", path, err)
|
||||
return fmt.Errorf("loading error: %s", err)
|
||||
}
|
||||
r.bundles[path] = bndl
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user