-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
58 lines (46 loc) · 1.21 KB
/
errors.go
File metadata and controls
58 lines (46 loc) · 1.21 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
package main
import (
"errors"
"fmt"
"os"
)
type APIKeyMissingError struct{}
type CostFileNotFoundError struct{}
type InjectError struct{ Char rune }
type JSONParseError struct{ Err error }
type OpenAIRequestError struct{ Err error }
type QuitError struct{}
type RerunError struct{}
type UnsupportedModelError struct{ Model string }
func (e APIKeyMissingError) Error() string {
return "CFOR_OPEN_API_KEY or OPENAI_API_KEY environment variable must be set"
}
func (e CostFileNotFoundError) Error() string {
return "Cost file not found"
}
func (e InjectError) Error() string {
return fmt.Sprintf("failed to inject character: %c", e.Char)
}
func (e JSONParseError) Error() string {
return fmt.Sprintf("JSON unmarshal failed: %v", e.Err)
}
func (e OpenAIRequestError) Error() string {
return fmt.Sprintf("OpenAI request failed: %v", e.Err)
}
func (q QuitError) Error() string {
return "quitting"
}
func (q RerunError) Error() string {
return "rerunning"
}
func (e UnsupportedModelError) Error() string {
return fmt.Sprintf("Unsupported model: %s", e.Model)
}
func (e UnsupportedModelError) Is(target error) bool {
return target == e
}
func HandleQuitError(err error) {
if errors.Is(err, QuitError{}) {
os.Exit(0)
}
}