-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
42 lines (35 loc) · 895 Bytes
/
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
package plist
import (
"errors"
"fmt"
"reflect"
)
// Unmarshal could be done, only to pointer
var ErrMustBePointer = errors.New("Value must be a pointer.")
// UnexpectedTokenError appears when parse found something unexpected in data stream
type UnexpectedTokenError struct {
Expected string
Got interface{}
Offset int64
}
func NewUnexpectedTokenError(expected string, got interface{}, offset int64) *UnexpectedTokenError {
return &UnexpectedTokenError{
expected, got, offset,
}
}
func (err *UnexpectedTokenError) Error() string {
return fmt.Sprintf("Unexpected token: Expects %s, got %#v (offset=%d)",
err.Expected,
err.Got,
err.Offset)
}
type CannotParseTypeError struct {
Value reflect.Value
}
func (err *CannotParseTypeError) Error() string {
n := err.Value.Type().Name()
if n == "" {
n = "<<unnamed>>"
}
return fmt.Sprintf("Cannot parse type %s", n)
}