asciigoat's core library
https://asciigoat.org/core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
793 B
45 lines
793 B
1 year ago
|
package reflection
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"fmt"
|
||
|
"reflect"
|
||
|
)
|
||
|
|
||
|
// An InvalidUnmarshalError describes an invalid argument passed to New.
|
||
|
// (It must be a non-nil pointer.)
|
||
|
type InvalidUnmarshalError struct {
|
||
|
Method string
|
||
|
Prefix string
|
||
|
|
||
|
reflect.Type
|
||
|
}
|
||
|
|
||
|
func (e *InvalidUnmarshalError) Error() string {
|
||
|
var buf bytes.Buffer
|
||
|
|
||
|
if e.Prefix != "" {
|
||
|
_, _ = fmt.Fprintf(&buf, "%s: ", e.Prefix)
|
||
|
}
|
||
|
|
||
|
method := e.Method
|
||
|
if method == "" {
|
||
|
method = "New"
|
||
|
}
|
||
|
|
||
|
_, _ = fmt.Fprintf(&buf, "%s(", method)
|
||
|
|
||
|
switch {
|
||
|
case e.Type == nil:
|
||
|
_, _ = buf.WriteString("nil")
|
||
|
case e.Type.Kind() != reflect.Pointer:
|
||
|
_, _ = fmt.Fprintf(&buf, "%s %s", "non-pointer", e.Type.String())
|
||
|
default:
|
||
|
_, _ = fmt.Fprintf(&buf, "%s %s", "nil", e.Type.String())
|
||
|
}
|
||
|
|
||
|
_, _ = buf.WriteString(")")
|
||
|
|
||
|
return buf.String()
|
||
|
}
|