-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy patherrors.go
83 lines (67 loc) · 2.53 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
72
73
74
75
76
77
78
79
80
81
82
83
package dice
import "errors"
var (
// ErrImpossibleDie is returned when an attempt to create a die with a
// negative number of sides is made.
ErrImpossibleDie = errors.New("die cannot have negative sides")
// ErrNilDie is returned when a die's passed reference is nil.
ErrNilDie = errors.New("nil die passed")
// ErrMaxRolls is returned when a maximum number of rolls/rerolls has been
// met or surpassed.
ErrMaxRolls = errors.New("max rolls reached")
// ErrUnrolled is returned when an operation that requires a rolled die is
// preformed on an unrolled die
ErrUnrolled = errors.New("die is unrolled")
// ErrRolled is returned when an attempt is made to roll a die that had been
// rolled already
ErrRolled = errors.New("die already rolled")
// ErrRerolled is returned when it must be noted that a die's value has
// changed due to being rerolled.
ErrRerolled = errors.New("die rerolled")
// ErrInvalidExpression is returned when a dice expression is invalid or
// there is a general issue evaluating it.
ErrInvalidExpression = errors.New("invalid expression")
// ErrImpossibleRoll is returned when a given dice roll is deemed
// impossible, illogical, or will never be able to yield a result. As an
// example, a roll of "3d6r<6" should return this error at some stage in its
// evaluation, as no die in the set will ever be able to settle with the
// given reroll modifier.
ErrImpossibleRoll = errors.New("impossible roll")
// ErrContextKeyMissing is returned if a context key is not found in a
// request context.
ErrContextKeyMissing = errors.New("context key missing")
// ErrMaxDepth is returned if a replacement operation recurses beyond
// MaxDepth.
ErrMaxDepth = errors.New("max replacement depth")
)
// ErrNotImplemented is an error returned when a feature is not yet implemented.
type ErrNotImplemented struct {
message string
}
// NewErrNotImplemented returns a new not implemented error.
func NewErrNotImplemented(message string) *ErrNotImplemented {
return &ErrNotImplemented{
message: message,
}
}
func (e *ErrNotImplemented) Error() string {
return e.message
}
// ErrParseError is an error encountered when parsing a string into dice
// notation.
type ErrParseError struct {
Notation string
NotationElem string
ValueElem string
Message string
}
func (e *ErrParseError) Error() string {
if e.Message == "" {
return "parsing dice string " +
quote(e.Notation) + ": cannot parse " +
quote(e.ValueElem) + " as " +
quote(e.NotationElem)
}
return "parsing dice " +
quote(e.Notation) + e.Message
}