-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
102 lines (93 loc) · 3.06 KB
/
Copy patherrors.go
File metadata and controls
102 lines (93 loc) · 3.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
91
92
93
94
95
96
97
98
99
100
101
102
package acpruntime
import "fmt"
// CleanupStatus describes durable provider-side session cleanup after a failed
// session operation. It does not describe process/connection teardown.
//
// - CleanupSucceeded: the runtime deleted the durable session (e.g. Create
// failed after session/new and session/delete completed).
// - CleanupFailed: durable delete was attempted and failed; SessionID may still
// exist on the provider.
// - CleanupNotAttempted: durable delete was intentionally skipped (e.g. Resume
// initial-config failure must not destroy an existing session).
type CleanupStatus string
const (
CleanupNotAttempted CleanupStatus = "not_attempted"
CleanupSucceeded CleanupStatus = "succeeded"
CleanupFailed CleanupStatus = "failed"
)
type ErrorKind string
const (
ErrorAuthentication ErrorKind = "authentication"
ErrorCreate ErrorKind = "create"
ErrorFork ErrorKind = "fork"
ErrorInitialConfig ErrorKind = "initial_config"
ErrorLoad ErrorKind = "load"
ErrorList ErrorKind = "list"
ErrorPermission ErrorKind = "permission"
ErrorProcess ErrorKind = "process"
ErrorProtocol ErrorKind = "protocol"
ErrorResume ErrorKind = "resume"
ErrorSessionClosed ErrorKind = "session_closed"
ErrorSystemPrompt ErrorKind = "system_prompt"
ErrorTurnCancelled ErrorKind = "turn_cancelled"
ErrorTurnCoalesced ErrorKind = "turn_coalesced"
ErrorTurnTimeout ErrorKind = "turn_timeout"
ErrorTurnWithdrawn ErrorKind = "turn_withdrawn"
)
type RuntimeError struct {
Kind ErrorKind
Op string
Msg string
Cause error
SessionID string
CleanupStatus CleanupStatus
CleanupError error
}
func (e *RuntimeError) Error() string {
if e == nil {
return "<nil>"
}
var base string
switch {
case e.Op != "" && e.Msg != "" && e.Cause != nil:
base = fmt.Sprintf("%s: %s: %v", e.Op, e.Msg, e.Cause)
case e.Op != "" && e.Msg != "":
base = fmt.Sprintf("%s: %s", e.Op, e.Msg)
case e.Msg != "":
base = e.Msg
case e.Cause != nil:
base = e.Cause.Error()
default:
base = string(e.Kind)
}
// Append structured fields that hosts often log only via Error(). SessionID
// and cleanup outcome are operationally critical after failed Create/Resume.
if e.SessionID != "" || e.CleanupStatus != "" {
if e.SessionID != "" && e.CleanupStatus != "" {
base = fmt.Sprintf("%s (session_id=%s cleanup=%s)", base, e.SessionID, e.CleanupStatus)
} else if e.SessionID != "" {
base = fmt.Sprintf("%s (session_id=%s)", base, e.SessionID)
} else {
base = fmt.Sprintf("%s (cleanup=%s)", base, e.CleanupStatus)
}
}
if e.CleanupError != nil {
base = fmt.Sprintf("%s (cleanup_error=%v)", base, e.CleanupError)
}
return base
}
func (e *RuntimeError) Unwrap() error {
if e == nil {
return nil
}
return e.Cause
}
func wrapError(kind ErrorKind, op, msg string, err error) error {
if err == nil {
return &RuntimeError{Kind: kind, Op: op, Msg: msg}
}
if _, ok := err.(*RuntimeError); ok {
return err
}
return &RuntimeError{Kind: kind, Op: op, Msg: msg, Cause: err}
}