-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
138 lines (117 loc) · 2.96 KB
/
Copy patherrors.go
File metadata and controls
138 lines (117 loc) · 2.96 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package codexcw
import (
"errors"
"fmt"
)
var (
// ErrPromptRequired is returned when a non-resume run has no prompt input.
ErrPromptRequired = errors.New("codexcw: prompt or stdin is required")
// ErrInvalidRequest is wrapped by validation failures in Request.
ErrInvalidRequest = errors.New("codexcw: invalid request")
)
// ExitError reports a non-zero codex process exit.
type ExitError struct {
// Code is the process exit code.
Code int
// Stderr is the captured stderr tail.
Stderr string
// LastEvent is the last decoded event before process exit.
LastEvent *Event
// Err is the wrapped process error.
Err error
}
// Error formats the process exit failure.
func (e *ExitError) Error() string {
if e == nil {
return ""
}
if e.Err != nil {
return fmt.Sprintf("codex exited with code %d: %v", e.Code, e.Err)
}
return fmt.Sprintf("codex exited with code %d", e.Code)
}
// Unwrap returns the wrapped process error.
func (e *ExitError) Unwrap() error {
if e == nil {
return nil
}
return e.Err
}
// DecodeError reports malformed JSONL from codex stdout.
type DecodeError struct {
// Line is the one-based JSONL line number.
Line int
// Raw is the malformed line when available.
Raw []byte
// Err is the wrapped decode error.
Err error
}
// Error formats the JSONL decode failure.
func (e *DecodeError) Error() string {
if e == nil {
return ""
}
return fmt.Sprintf("decode codex JSONL line %d: %v", e.Line, e.Err)
}
// Unwrap returns the wrapped decode error.
func (e *DecodeError) Unwrap() error {
if e == nil {
return nil
}
return e.Err
}
// CodexError reports a top-level error or failed turn event from Codex.
type CodexError struct {
// Event is the Codex error event.
Event Event
}
// Error formats the Codex error event.
func (e *CodexError) Error() string {
if e == nil {
return ""
}
if e.Event.Error != nil && e.Event.Error.Message != "" {
return "codex error: " + e.Event.Error.Message
}
if e.Event.TurnFailed != nil && e.Event.TurnFailed.Error.Message != "" {
return "codex turn failed: " + e.Event.TurnFailed.Error.Message
}
return "codex error event"
}
// HandlerError wraps an error returned by a Handler.
type HandlerError struct {
// Err is the handler error.
Err error
}
// Error formats the handler failure.
func (e *HandlerError) Error() string {
if e == nil || e.Err == nil {
return "codex event handler failed"
}
return "codex event handler failed: " + e.Err.Error()
}
// Unwrap returns the handler error.
func (e *HandlerError) Unwrap() error {
if e == nil {
return nil
}
return e.Err
}
// GroupError reports one or more failed runs from RunMany.
type GroupError struct {
// Results contains every run result, including failed runs.
Results []GroupResult
}
// Error formats the number of failed runs.
func (e *GroupError) Error() string {
if e == nil {
return ""
}
failed := 0
for _, result := range e.Results {
if result.Err != nil {
failed++
}
}
return fmt.Sprintf("%d codex run(s) failed", failed)
}