-
Notifications
You must be signed in to change notification settings - Fork 95
/
errors.go
66 lines (52 loc) · 1.71 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
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package stun
import "errors"
// DecodeErr records an error and place when it is occurred.
//
//nolint:errname
type DecodeErr struct {
Place DecodeErrPlace
Message string
}
// IsInvalidCookie returns true if error means that magic cookie
// value is invalid.
func (e DecodeErr) IsInvalidCookie() bool {
return e.Place == DecodeErrPlace{"message", "cookie"}
}
// IsPlaceParent reports if error place parent is p.
func (e DecodeErr) IsPlaceParent(p string) bool {
return e.Place.Parent == p
}
// IsPlaceChildren reports if error place children is c.
func (e DecodeErr) IsPlaceChildren(c string) bool {
return e.Place.Children == c
}
// IsPlace reports if error place is p.
func (e DecodeErr) IsPlace(p DecodeErrPlace) bool {
return e.Place == p
}
// DecodeErrPlace records a place where error is occurred.
type DecodeErrPlace struct {
Parent string
Children string
}
func (p DecodeErrPlace) String() string {
return p.Parent + "/" + p.Children
}
func (e DecodeErr) Error() string {
return "BadFormat for " + e.Place.String() + ": " + e.Message
}
func newDecodeErr(parent, children, message string) *DecodeErr {
return &DecodeErr{
Place: DecodeErrPlace{Parent: parent, Children: children},
Message: message,
}
}
func newAttrDecodeErr(children, message string) *DecodeErr {
return newDecodeErr("attribute", children, message)
}
// ErrAttributeSizeInvalid means that decoded attribute size is invalid.
var ErrAttributeSizeInvalid = errors.New("attribute size is invalid")
// ErrAttributeSizeOverflow means that decoded attribute size is too big.
var ErrAttributeSizeOverflow = errors.New("attribute size overflow")