util-go/reflect/error.go

41 lines
627 B
Go
Raw Normal View History

package reflect
import (
"fmt"
"strings"
)
type ErrCanNotConvertType struct {
value interface{}
2019-01-07 14:35:34 +00:00
from Type
to Type
reason []string
}
func (e ErrCanNotConvertType) Error() string {
var (
reason = strings.Join(e.reason, ", ")
)
if reason != "" {
reason = ", reason: " + reason
}
return fmt.Sprintf(
"Can not convert '%#v' of type '%s' to '%s'%s",
e.value,
e.from,
e.to,
reason,
)
}
2019-01-07 14:35:34 +00:00
func NewErrCanNotConvertType(value interface{}, from Type, to Type, reason ...string) ErrCanNotConvertType {
return ErrCanNotConvertType{
value: value,
from: from,
to: to,
reason: reason,
}
}