-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
54 lines (43 loc) · 1.18 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
package tlv
import (
"errors"
"fmt"
)
type constantError string
const (
ErrTagHasNoBytes constantError = "tag has no bytes"
ErrTagShouldHave2Bytes constantError = "tag should have 2 bytes"
ErrTagTooLong constantError = "tag too long"
ErrLengthHasNoBytes constantError = "length has no bytes"
ErrLengthBiggerThanData constantError = "length bigger than data"
ErrLengthFormatError constantError = "length format error"
ErrValueTooShort constantError = "value too short"
)
func (e constantError) Error() string {
return string(e)
}
type TLVDecodeError struct {
err error
constError constantError
}
func (e TLVDecodeError) Error() string {
return e.err.Error()
}
func (e TLVDecodeError) Is(err error) bool {
if err == e.constError {
return true
}
return errors.Is(e.err, err)
}
func newTLVDecodeError(constError constantError, message string) TLVDecodeError {
return TLVDecodeError{
err: errors.New(message),
constError: constError,
}
}
func newTLVDecodeErrorf(constError constantError, message string, args ...interface{}) TLVDecodeError {
return TLVDecodeError{
err: fmt.Errorf(message, args...),
constError: constError,
}
}