-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
49 lines (40 loc) · 975 Bytes
/
error.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
package llm
import (
"fmt"
)
////////////////////////////////////////////////////////////////////////////////
// GLOBALS
const (
ErrSuccess Err = iota
ErrNotFound
ErrBadParameter
ErrNotImplemented
ErrConflict
)
////////////////////////////////////////////////////////////////////////////////
// TYPES
// Errors
type Err int
////////////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
func (e Err) Error() string {
switch e {
case ErrSuccess:
return "success"
case ErrNotFound:
return "not found"
case ErrBadParameter:
return "bad parameter"
case ErrNotImplemented:
return "not implemented"
case ErrConflict:
return "conflict"
}
return fmt.Sprintf("error code %d", int(e))
}
func (e Err) With(args ...interface{}) error {
return fmt.Errorf("%w: %s", e, fmt.Sprint(args...))
}
func (e Err) Withf(format string, args ...interface{}) error {
return fmt.Errorf("%w: %s", e, fmt.Sprintf(format, args...))
}