-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
71 lines (58 loc) · 2.43 KB
/
errors.go
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
package polo
import (
"errors"
"fmt"
"reflect"
"strings"
)
var (
// zeroVal represents the zero value of reflect.Value.
// It acts as a marker for encoding/decoding nil values.
zeroVal = reflect.ValueOf(nil)
// nilValue is an error for when a WireNull is encountered during reflective decoding.
// It acts a signal for error and value handlers.
errNilValue = errors.New("nil value")
// ErrObjectNotPtr is an error for when a non pointer object is passed to the Depolorize function
ErrObjectNotPtr = errors.New("object not a pointer")
// ErrObjectNotSettable is an error for when a non-settable pointer is passed to the Depolorize function
ErrObjectNotSettable = errors.New("object is not settable")
// ErrInsufficientWire is an error for when the data in depolorizer is exhausted
ErrInsufficientWire = errors.New("insufficient data in wire for decode")
)
// MalformedTagError is an error for when a consumed varint for a tag is malformed
type MalformedTagError struct {
msg string
}
// Error implements the error interface for MalformedTagError
func (err MalformedTagError) Error() string {
return fmt.Sprintf("malformed tag: %v", err.msg)
}
// IncompatibleWireError is an error for when an object cannot be decoded from some wire data
type IncompatibleWireError struct {
msg string
}
// Error implements the error interface for IncompatibleWireError
func (err IncompatibleWireError) Error() string {
return fmt.Sprintf("incompatible wire: %v", err.msg)
}
// IncompatibleWireType returns an IncompatibleWireError formatted to express
// the mismatch between an unexpected wire type and the list of expected ones.
func IncompatibleWireType(actual WireType, expected ...WireType) IncompatibleWireError {
expects := make([]string, 0, len(expected))
for _, wire := range expected {
expects = append(expects, wire.String())
}
data := "{" + strings.Join(expects, `, `) + `}`
return IncompatibleWireError{fmt.Sprintf("unexpected wiretype '%v'. expected one of: %v", actual, data)}
}
// IncompatibleValueError is an error for when an incompatible value is used for encoding
type IncompatibleValueError struct {
msg string
}
// Error implements the error interface for IncompatibleValueError
func (err IncompatibleValueError) Error() string {
return fmt.Sprintf("incompatible value error: %v", err.msg)
}
func UnsupportedTypeError(t reflect.Type) IncompatibleValueError {
return IncompatibleValueError{fmt.Sprintf("unsupported type: %v [%v]", t, t.Kind())}
}