-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy patherrors.go
More file actions
115 lines (100 loc) · 3.56 KB
/
Copy patherrors.go
File metadata and controls
115 lines (100 loc) · 3.56 KB
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
112
113
114
115
package fsrs
// ErrorCode identifies a specific error condition returned by FSRS operations.
type ErrorCode int
const (
_ ErrorCode = iota // reserved
ErrCodeInvalidInput
ErrCodeManualRating
ErrCodeInvalidRating
ErrCodeManualStateRequired
ErrCodeManualDueRequired
ErrCodeInvalidWeightsLength
ErrCodeInvalidWeightsValue
ErrCodeInvalidDecay
ErrCodeInvalidRetention
ErrCodeInvalidMaxInterval
ErrCodeInvalidSteps
)
// Error represents a structured FSRS error with a machine-readable code
// and a human-readable message.
type Error struct {
Code ErrorCode
Message string
}
// Error returns the human-readable error message. Implements the error interface.
// It is nil-safe: a nil *Error returns "fsrs: <nil>" rather than panicking.
func (e *Error) Error() string {
if e == nil {
return "fsrs: <nil>"
}
return e.Message
}
// Is reports whether this error matches the target by comparing ErrorCode values.
// Returns true when both are nil. Returns false when only one is nil or the
// target is not an *Error.
func (e *Error) Is(target error) bool {
if e == nil {
return target == nil
}
t, ok := target.(*Error)
if !ok || t == nil {
return false
}
return e.Code == t.Code
}
var (
// ErrManualRating is returned by Rollback when the review log entry represents
// a manual (non-graded) operation that cannot be rolled back.
ErrManualRating = &Error{
Code: ErrCodeManualRating,
Message: "fsrs: cannot rollback a manual rating",
}
// ErrInvalidRating is returned by Rollback when the review log rating is
// outside the valid range [Again, Easy].
ErrInvalidRating = &Error{
Code: ErrCodeInvalidRating,
Message: "fsrs: invalid rating for rollback",
}
// ErrManualStateRequired is returned by Reschedule when a manual review entry
// is missing the required State field.
ErrManualStateRequired = &Error{
Code: ErrCodeManualStateRequired,
Message: "fsrs: state is required for manual rating",
}
// ErrManualDueRequired is returned by Reschedule when a manual review entry
// with a non-New state is missing the required Due field.
ErrManualDueRequired = &Error{
Code: ErrCodeManualDueRequired,
Message: "fsrs: due is required for manual rating when state is not New",
}
// ErrInvalidWeightsLength is returned when migrating weights with a length other than 17, 19, or 21.
ErrInvalidWeightsLength = &Error{
Code: ErrCodeInvalidWeightsLength,
Message: "fsrs: invalid weights slice length: must be 17, 19, or 21",
}
// ErrInvalidWeightsValue matches errors returned when any weight parameter is NaN or Inf.
ErrInvalidWeightsValue = &Error{
Code: ErrCodeInvalidWeightsValue,
Message: "fsrs: invalid weights value: must be finite",
}
// ErrInvalidDecay matches errors returned by Validate when W[20] (decay) is not positive.
ErrInvalidDecay = &Error{
Code: ErrCodeInvalidDecay,
Message: "fsrs: invalid weight W[20]: must be > 0",
}
// ErrInvalidRetention matches errors returned by Validate when RequestRetention is outside (0, 1].
ErrInvalidRetention = &Error{
Code: ErrCodeInvalidRetention,
Message: "fsrs: invalid RequestRetention: must be in (0, 1]",
}
// ErrInvalidMaxInterval matches errors returned by Validate when MaximumInterval is outside (0, 36500].
ErrInvalidMaxInterval = &Error{
Code: ErrCodeInvalidMaxInterval,
Message: "fsrs: invalid MaximumInterval: must be in (0, 36500]",
}
// ErrInvalidSteps matches errors returned by Validate when a learning or relearning step is invalid.
ErrInvalidSteps = &Error{
Code: ErrCodeInvalidSteps,
Message: "fsrs: invalid steps: must be finite and >= 0",
}
)