mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Error type MalformedYamlError created. api.internal.target.kusttarget.accumulateResources checks for this new error type
This commit is contained in:
@@ -19,6 +19,16 @@ func (e YamlFormatError) Error() string {
|
||||
return fmt.Sprintf("YAML file [%s] encounters a format error.\n%s\n", e.Path, e.ErrorMsg)
|
||||
}
|
||||
|
||||
// MalformedYamlError represents an error that occurred while trying to decode a given YAML.
|
||||
type MalformedYamlError struct {
|
||||
Path string
|
||||
ErrorMsg string
|
||||
}
|
||||
|
||||
func (e MalformedYamlError) Error() string {
|
||||
return fmt.Sprintf("%s in File: %s", e.ErrorMsg, e.Path)
|
||||
}
|
||||
|
||||
// Handler handles YamlFormatError
|
||||
func Handler(e error, path string) error {
|
||||
if isYAMLSyntaxError(e) {
|
||||
@@ -27,9 +37,19 @@ func Handler(e error, path string) error {
|
||||
ErrorMsg: e.Error(),
|
||||
}
|
||||
}
|
||||
if IsMalformedYAMLError(e) {
|
||||
return MalformedYamlError{
|
||||
Path: path,
|
||||
ErrorMsg: e.Error(),
|
||||
}
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
func isYAMLSyntaxError(e error) bool {
|
||||
return strings.Contains(e.Error(), "error converting YAML to JSON") || strings.Contains(e.Error(), "error unmarshaling JSON")
|
||||
}
|
||||
|
||||
func IsMalformedYAMLError(e error) bool {
|
||||
return strings.Contains(e.Error(), "MalformedYAMLError")
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/api/ifc"
|
||||
"sigs.k8s.io/kustomize/api/internal/accumulator"
|
||||
"sigs.k8s.io/kustomize/api/internal/builtins"
|
||||
"sigs.k8s.io/kustomize/api/internal/kusterr"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinhelpers"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
||||
@@ -405,6 +406,9 @@ func (kt *KustTarget) accumulateResources(
|
||||
if errors.Is(errF, load.ErrorHTTP) {
|
||||
return nil, errF
|
||||
}
|
||||
if kusterr.IsMalformedYAMLError(errF) { // Some error occured while tyring to decode YAML file
|
||||
return nil, errF
|
||||
}
|
||||
ldr, err := kt.ldr.New(path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(
|
||||
|
||||
@@ -294,7 +294,7 @@ func (r *ByteReader) decode(originalYAML string, index int, decoder *yaml.Decode
|
||||
return nil, io.EOF
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
return nil, errors.WrapPrefixf(err, "MalformedYAMLError")
|
||||
}
|
||||
|
||||
if yaml.IsYNodeEmptyDoc(node) {
|
||||
|
||||
Reference in New Issue
Block a user