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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
package thrift
import (
"errors"
"fmt"
"io"
"strings"
)
type MissingField struct {
Field Field
}
func (e *MissingField) Error() string {
return fmt.Sprintf("missing required field: %s", e.Field)
}
type TypeMismatch struct {
Expect Type
Found Type
item string
}
func (e *TypeMismatch) Error() string {
return fmt.Sprintf("%s type mismatch: expected %s but found %s", e.item, e.Expect, e.Found)
}
type decodeError struct {
base error
path []error
}
func (e *decodeError) Error() string {
s := strings.Builder{}
s.Grow(256)
s.WriteString("decoding thrift payload: ")
if len(e.path) != 0 {
n := len(e.path) - 1
for i := n; i >= 0; i-- {
if i < n {
s.WriteString(" → ")
}
s.WriteString(e.path[i].Error())
}
s.WriteString(": ")
}
s.WriteString(e.base.Error())
return s.String()
}
func (e *decodeError) Unwrap() error { return e.base }
func with(base, elem error) error {
if errors.Is(base, io.EOF) {
return base
}
e, _ := base.(*decodeError)
if e == nil {
e = &decodeError{base: base}
}
e.path = append(e.path, elem)
return e
}
type decodeErrorField struct {
cause Field
}
func (d *decodeErrorField) Error() string {
return d.cause.String()
}
type decodeErrorList struct {
cause List
index int
}
func (d *decodeErrorList) Error() string {
return fmt.Sprintf("%d/%d:%s", d.index, d.cause.Size, d.cause)
}
type decodeErrorSet struct {
cause Set
index int
}
func (d *decodeErrorSet) Error() string {
return fmt.Sprintf("%d/%d:%s", d.index, d.cause.Size, d.cause)
}
type decodeErrorMap struct {
cause Map
index int
}
func (d *decodeErrorMap) Error() string {
return fmt.Sprintf("%d/%d:%s", d.index, d.cause.Size, d.cause)
}
func dontExpectEOF(err error) error {
switch err {
case nil:
return nil
case io.EOF:
return io.ErrUnexpectedEOF
default:
return err
}
}
|