remove apimachinery dependency from internal/error package

This commit is contained in:
Jingfang Liu
2018-10-08 14:12:00 -07:00
parent 8e0c55f9fa
commit 08da2455dd
2 changed files with 8 additions and 16 deletions

View File

@@ -19,8 +19,7 @@ package error
import (
"fmt"
"k8s.io/apimachinery/pkg/util/yaml"
"strings"
)
// YamlFormatError represents error with yaml file name where json/yaml format error happens.
@@ -35,11 +34,15 @@ func (e YamlFormatError) Error() string {
// Handler handles YamlFormatError
func Handler(e error, path string) error {
if err, ok := e.(yaml.YAMLSyntaxError); ok {
if isYAMLSyntaxError(e) {
return YamlFormatError{
Path: path,
ErrorMsg: err.Error(),
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")
}