|
| 1 | +package encoding |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "strconv" |
| 6 | + |
| 7 | + "github.com/layer5io/meshkit/errors" |
| 8 | +) |
| 9 | + |
| 10 | +const ( |
| 11 | + ErrDecodeYamlCode = "" |
| 12 | + ErrUnmarshalCode = "" |
| 13 | + ErrUnmarshalInvalidCode = "" |
| 14 | + ErrUnmarshalSyntaxCode = "" |
| 15 | + ErrUnmarshalTypeCode = "" |
| 16 | + ErrUnmarshalUnsupportedTypeCode = "" |
| 17 | + ErrUnmarshalUnsupportedValueCode = "" |
| 18 | +) |
| 19 | + |
| 20 | +// ErrDecodeYaml is the error when the yaml unmarshal fails |
| 21 | +func ErrDecodeYaml(err error) error { |
| 22 | + return errors.New(ErrDecodeYamlCode, errors.Alert, []string{"Error occurred while decoding YAML"}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid YAML object"}) |
| 23 | +} |
| 24 | + |
| 25 | +func ErrUnmarshal(err error) error { |
| 26 | + return errors.New(ErrUnmarshalCode, errors.Alert, []string{"Unmarshal unknown error: "}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"}) |
| 27 | +} |
| 28 | + |
| 29 | +func ErrUnmarshalInvalid(err error, typ reflect.Type) error { |
| 30 | + return errors.New(ErrUnmarshalInvalidCode, errors.Alert, []string{"Unmarshal invalid error for type: ", typ.String()}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"}) |
| 31 | +} |
| 32 | + |
| 33 | +func ErrUnmarshalSyntax(err error, offset int64) error { |
| 34 | + return errors.New(ErrUnmarshalSyntaxCode, errors.Alert, []string{"Unmarshal syntax error at offest: ", strconv.Itoa(int(offset))}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"}) |
| 35 | +} |
| 36 | + |
| 37 | +func ErrUnmarshalType(err error, value string) error { |
| 38 | + return errors.New(ErrUnmarshalTypeCode, errors.Alert, []string{"Unmarshal type error at key: %s. Error: %s", value}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"}) |
| 39 | +} |
| 40 | + |
| 41 | +func ErrUnmarshalUnsupportedType(err error, typ reflect.Type) error { |
| 42 | + return errors.New(ErrUnmarshalUnsupportedTypeCode, errors.Alert, []string{"Unmarshal unsupported type error at key: ", typ.String()}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"}) |
| 43 | +} |
| 44 | + |
| 45 | +func ErrUnmarshalUnsupportedValue(err error, value reflect.Value) error { |
| 46 | + return errors.New(ErrUnmarshalUnsupportedValueCode, errors.Alert, []string{"Unmarshal unsupported value error at key: ", value.String()}, []string{err.Error()}, []string{"Invalid object format"}, []string{"Make sure to input a valid JSON object"}) |
| 47 | +} |
0 commit comments