-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
90 lines (78 loc) · 2.06 KB
/
error.go
File metadata and controls
90 lines (78 loc) · 2.06 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
package llama
import "fmt"
///////////////////////////////////////////////////////////////////////////////
// TYPES
// Error represents an error code
type Error int
///////////////////////////////////////////////////////////////////////////////
// ERROR CODES
const (
ErrSuccess Error = iota
ErrInvalidContext
ErrInvalidModel
ErrInvalidArgument
ErrIndexOutOfRange
ErrKeyNotFound
ErrTypeMismatch
ErrInvalidToken
ErrInvalidBatch
ErrBatchFull
ErrNoKVSlot
ErrOpenFailed
ErrNotFound
ErrModelNotLoaded
ErrNotEmbeddingModel
)
///////////////////////////////////////////////////////////////////////////////
// STRINGIFY
func (e Error) String() string {
switch e {
case ErrSuccess:
return "success"
case ErrInvalidContext:
return "invalid context"
case ErrInvalidModel:
return "invalid model"
case ErrInvalidArgument:
return "invalid argument"
case ErrIndexOutOfRange:
return "index out of range"
case ErrKeyNotFound:
return "metadata key not found"
case ErrTypeMismatch:
return "metadata type mismatch"
case ErrInvalidToken:
return "invalid token"
case ErrInvalidBatch:
return "invalid batch"
case ErrBatchFull:
return "batch is full"
case ErrNoKVSlot:
return "no KV cache slot available"
case ErrOpenFailed:
return "failed to open file"
case ErrNotFound:
return "not found"
case ErrModelNotLoaded:
return "model not loaded"
case ErrNotEmbeddingModel:
return "model does not support embeddings"
default:
return fmt.Sprintf("error(%d)", int(e))
}
}
///////////////////////////////////////////////////////////////////////////////
// ERROR INTERFACE
func (e Error) Error() string {
return e.String()
}
///////////////////////////////////////////////////////////////////////////////
// WRAPPING
// With returns a new error wrapping this error with additional context
func (e Error) With(msg string) error {
return fmt.Errorf("%w: %s", e, msg)
}
// Withf returns a new error wrapping this error with formatted context
func (e Error) Withf(format string, args ...any) error {
return fmt.Errorf("%w: %s", e, fmt.Sprintf(format, args...))
}