1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
package document
import (
"fmt"
"reflect"
)
// UnmarshalTypeError is an error type representing an error
// unmarshaling a Smithy document to a Go value type. This is different
// from UnmarshalError in that it does not wrap an underlying error type.
type UnmarshalTypeError struct {
Value string
Type reflect.Type
}
// Error returns the string representation of the error.
// Satisfying the error interface.
func (e *UnmarshalTypeError) Error() string {
return fmt.Sprintf("unmarshal failed, cannot unmarshal %s into Go value type %s",
e.Value, e.Type.String())
}
// An InvalidUnmarshalError is an error type representing an invalid type
// encountered while unmarshaling a Smithy document to a Go value type.
type InvalidUnmarshalError struct {
Type reflect.Type
}
// Error returns the string representation of the error.
// Satisfying the error interface.
func (e *InvalidUnmarshalError) Error() string {
var msg string
if e.Type == nil {
msg = "cannot unmarshal to nil value"
} else if e.Type.Kind() != reflect.Ptr {
msg = fmt.Sprintf("cannot unmarshal to non-pointer value, got %s", e.Type.String())
} else {
msg = fmt.Sprintf("cannot unmarshal to nil value, %s", e.Type.String())
}
return fmt.Sprintf("unmarshal failed, %s", msg)
}
// An UnmarshalError wraps an error that occurred while unmarshaling a
// Smithy document into a Go type. This is different from
// UnmarshalTypeError in that it wraps the underlying error that occurred.
type UnmarshalError struct {
Err error
Value string
Type reflect.Type
}
// Unwrap returns the underlying unmarshaling error
func (e *UnmarshalError) Unwrap() error {
return e.Err
}
// Error returns the string representation of the error.
// Satisfying the error interface.
func (e *UnmarshalError) Error() string {
return fmt.Sprintf("unmarshal failed, cannot unmarshal %q into %s, %v",
e.Value, e.Type.String(), e.Err)
}
// An InvalidMarshalError is an error type representing an error
// occurring when marshaling a Go value type.
type InvalidMarshalError struct {
Message string
}
// Error returns the string representation of the error.
// Satisfying the error interface.
func (e *InvalidMarshalError) Error() string {
return fmt.Sprintf("marshal failed, %s", e.Message)
}
|