-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_errors.go
37 lines (30 loc) · 1.09 KB
/
json_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
package jogson
import (
"errors"
"fmt"
)
var (
typeConversionErrStr = "%T could not be converted to %T"
keyNotFoundErrStr = "'%v'"
indexOutOfRangeErrStr = "[%v] with length %v"
invalidTime = "'%v' could not be parsed as time"
)
var (
TypeConversionErr = errors.New("type conversion error")
KeyNotFoundErr = errors.New("key was not found")
IndexOutOfRangeErr = errors.New("index out of range")
TimeTypeConversionErr = errors.New("time conversion error")
InvalidTimeErr = errors.New("invalid time")
)
func createTypeConversionErr(fromType any, toType any) error {
return fmt.Errorf("%w: %w", TypeConversionErr, fmt.Errorf(typeConversionErrStr, fromType, toType))
}
func createKeyNotFoundErr(key string) error {
return fmt.Errorf("%w: %w", KeyNotFoundErr, fmt.Errorf(keyNotFoundErrStr, key))
}
func createIndexOutOfRangeErr(i int, length int) error {
return fmt.Errorf("%w: %w", IndexOutOfRangeErr, fmt.Errorf(indexOutOfRangeErrStr, i, length))
}
func createNewInvalidTimeErr(v any) error {
return fmt.Errorf("%w: %w", InvalidTimeErr, fmt.Errorf(invalidTime, v))
}