mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
improve error messages
This commit is contained in:
@@ -105,7 +105,7 @@ func (lc *localizer) load() (*types.Kustomization, string, error) {
|
||||
var kust types.Kustomization
|
||||
err = (&kust).Unmarshal(content)
|
||||
if err != nil {
|
||||
return nil, "", errors.WrapPrefixf(err, "invalid kustomization")
|
||||
return nil, "", errors.Wrap(err)
|
||||
}
|
||||
|
||||
// Localize intentionally does not replace legacy fields to return a localized kustomization
|
||||
|
||||
@@ -228,7 +228,7 @@ suffix: invalid`,
|
||||
|
||||
err := Run("/a", "", "", fSysTest)
|
||||
require.EqualError(t, err,
|
||||
`unable to localize target "/a": invalid kustomization: kustomization unmarshal error: error unmarshaling JSON: while decoding JSON: json: unknown field "suffix"`)
|
||||
`unable to localize target "/a": invalid Kustomization: error unmarshaling JSON: while decoding JSON: json: unknown field "suffix"`)
|
||||
|
||||
checkFSys(t, fSysExpected, fSysTest)
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ radon
|
||||
t.Fatalf("expected an error")
|
||||
}
|
||||
assert.Contains(t, err.Error(),
|
||||
"kustomization unmarshal error: error converting YAML to JSON: yaml: unmarshal errors:\n"+
|
||||
"invalid Kustomization: error converting YAML to JSON: yaml: unmarshal errors:\n"+
|
||||
" line 13: key \"literals\" already set in map\n line 18: key \"files\" already set in map")
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ package types
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
@@ -317,7 +318,7 @@ func (k *Kustomization) EnforceFields() []string {
|
||||
// Unmarshal replace k with the content in YAML input y
|
||||
func (k *Kustomization) Unmarshal(y []byte) error {
|
||||
if err := yaml.UnmarshalStrict(y, &k); err != nil {
|
||||
return fmt.Errorf("kustomization unmarshal error: %w", err)
|
||||
return errors.WrapPrefixf(err, "invalid Kustomization")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ unknown: foo`)
|
||||
if err == nil {
|
||||
t.Fatalf("expect an error")
|
||||
}
|
||||
expect := "kustomization unmarshal error: error unmarshaling JSON: while decoding JSON: json: unknown field \"unknown\""
|
||||
expect := "invalid Kustomization: error unmarshaling JSON: while decoding JSON: json: unknown field \"unknown\""
|
||||
if err.Error() != expect {
|
||||
t.Fatalf("expect %v but got: %v", expect, err.Error())
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ foo:
|
||||
}
|
||||
|
||||
_, err = mf.Read()
|
||||
if err == nil || err.Error() != "kustomization unmarshal error: error unmarshaling JSON: while decoding JSON: json: unknown field \"foo\"" {
|
||||
if err == nil || err.Error() != "invalid Kustomization: error unmarshaling JSON: while decoding JSON: json: unknown field \"foo\"" {
|
||||
t.Fatalf("Expect an unknown field error but got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user