-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgt_util_err.go
41 lines (34 loc) · 1.16 KB
/
gt_util_err.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
package gt
import (
"fmt"
"io"
)
var (
errInvalidChar = fmt.Errorf(`invalid character`)
errFormatMismatch = fmt.Errorf(`format mismatch`)
errLengthMismatch = fmt.Errorf(`length mismatch`)
errTerNullBool = fmt.Errorf(`[gt] can't convert ternary null to boolean`)
errUnrecLength = fmt.Errorf(`unrecognized length`)
errDigitEof = fmt.Errorf(`expected digit, got %w`, io.EOF)
errEmptySegment = fmt.Errorf(`[gt] unexpected empty URL segment`)
)
func errParse(ptr *error, src string, typ string) {
if *ptr != nil {
*ptr = fmt.Errorf(`[gt] failed to parse %q into %v: %w`, src, typ, *ptr)
}
}
func errInvalidCharAt(src string, ind int) error {
for _, char := range src[ind:] {
return fmt.Errorf(`[gt] invalid character %q in position %v`, char, ind)
}
return errInvalidChar
}
func errJsonString(src []byte, typ any) error {
return fmt.Errorf(`[gt] can't decode %q into %T: expected string`, src, typ)
}
func errScanType(tar, inp any) error {
return fmt.Errorf(`[gt] unrecognized input for type %T: type %T, value %v`, tar, inp, inp)
}
func errInvalidSegment(val string) error {
return fmt.Errorf(`[gt] unexpected invalid URL segment %q`, val)
}