-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.go
More file actions
218 lines (178 loc) · 5.53 KB
/
Copy patherrors.go
File metadata and controls
218 lines (178 loc) · 5.53 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package e2b
import (
"errors"
"fmt"
)
// Error is the base interface implemented by every SDK-specific error.
// It lets callers switch on a single interface via errors.As:
//
// var sErr e2b.Error
// if errors.As(err, &sErr) { ... }
type Error interface {
error
sandboxError()
}
// baseError is embedded by every concrete error type so they all satisfy
// Error automatically.
type baseError struct{}
func (baseError) sandboxError() {}
// SandboxError wraps arbitrary sandbox/API failures that don't have a more
// specific type.
type SandboxError struct {
baseError
Message string
Cause error
}
func (e *SandboxError) Error() string {
if e.Cause != nil {
return "e2b: " + e.Message + ": " + e.Cause.Error()
}
return "e2b: " + e.Message
}
func (e *SandboxError) Unwrap() error { return e.Cause }
func newSandboxError(msg string, cause error) *SandboxError {
return &SandboxError{Message: msg, Cause: cause}
}
// TimeoutError is returned when a request or sandbox operation times out.
// Mirrors Python's TimeoutException / JS TimeoutError.
type TimeoutError struct {
baseError
Message string
Cause error
}
func (e *TimeoutError) Error() string { return "e2b: timeout: " + e.Message }
func (e *TimeoutError) Unwrap() error { return e.Cause }
func (e *TimeoutError) Timeout() bool { return true }
func (e *TimeoutError) Temporary() bool { return true }
// InvalidArgumentError reports an invalid parameter.
type InvalidArgumentError struct {
baseError
Message string
}
func (e *InvalidArgumentError) Error() string { return "e2b: invalid argument: " + e.Message }
// NotEnoughSpaceError reports the sandbox has insufficient disk space.
type NotEnoughSpaceError struct {
baseError
Message string
}
func (e *NotEnoughSpaceError) Error() string { return "e2b: not enough space: " + e.Message }
// NotFoundError is deprecated. Prefer FileNotFoundError or SandboxNotFoundError.
type NotFoundError struct {
baseError
Message string
}
func (e *NotFoundError) Error() string { return "e2b: not found: " + e.Message }
// FileNotFoundError reports a missing file/directory in the sandbox.
type FileNotFoundError struct {
baseError
Path string
Message string
}
func (e *FileNotFoundError) Error() string {
if e.Path != "" {
return fmt.Sprintf("e2b: file not found: %s: %s", e.Path, e.Message)
}
return "e2b: file not found: " + e.Message
}
// SandboxNotFoundError reports that the sandbox is gone or never existed.
type SandboxNotFoundError struct {
baseError
SandboxID string
Message string
}
func (e *SandboxNotFoundError) Error() string {
if e.SandboxID != "" {
return fmt.Sprintf("e2b: sandbox %q not found: %s", e.SandboxID, e.Message)
}
return "e2b: sandbox not found: " + e.Message
}
// AuthenticationError reports invalid or missing credentials.
type AuthenticationError struct {
baseError
Message string
}
func (e *AuthenticationError) Error() string { return "e2b: authentication failed: " + e.Message }
// GitAuthError specializes AuthenticationError for Git credential failures.
type GitAuthError struct {
baseError
Message string
}
func (e *GitAuthError) Error() string { return "e2b: git authentication failed: " + e.Message }
// GitUpstreamError reports a missing upstream branch.
type GitUpstreamError struct {
baseError
Message string
}
func (e *GitUpstreamError) Error() string { return "e2b: git upstream error: " + e.Message }
// TemplateError reports template/envd incompatibility.
type TemplateError struct {
baseError
Message string
}
func (e *TemplateError) Error() string { return "e2b: template error: " + e.Message }
// RateLimitError reports HTTP 429.
type RateLimitError struct {
baseError
Message string
}
func (e *RateLimitError) Error() string { return "e2b: rate limit: " + e.Message }
// BuildError reports a template build failure.
type BuildError struct {
baseError
Message string
Cause error
}
func (e *BuildError) Error() string {
if e.Cause != nil {
return "e2b: build error: " + e.Message + ": " + e.Cause.Error()
}
return "e2b: build error: " + e.Message
}
func (e *BuildError) Unwrap() error { return e.Cause }
// FileUploadError reports a file upload failure during template build.
type FileUploadError struct {
baseError
Path string
Message string
Cause error
}
func (e *FileUploadError) Error() string {
return fmt.Sprintf("e2b: file upload error: %s: %s", e.Path, e.Message)
}
func (e *FileUploadError) Unwrap() error { return e.Cause }
// VolumeError reports a volume operation failure.
type VolumeError struct {
baseError
Message string
Cause error
}
func (e *VolumeError) Error() string {
if e.Cause != nil {
return "e2b: volume error: " + e.Message + ": " + e.Cause.Error()
}
return "e2b: volume error: " + e.Message
}
func (e *VolumeError) Unwrap() error { return e.Cause }
// CommandResult reports the outcome of a finished command.
type CommandResult struct {
Stdout string
Stderr string
ExitCode int32
Error string
}
// CommandExitError is returned by CommandHandle.Wait when a command exits
// non-zero. It embeds CommandResult so callers can inspect output.
type CommandExitError struct {
baseError
Result CommandResult
}
func (e *CommandExitError) Error() string {
return fmt.Sprintf("e2b: command exited with code %d: %s", e.Result.ExitCode, e.Result.Error)
}
// ErrNotImplemented is returned by stubbed features pending future work.
var ErrNotImplemented = errors.New("e2b: not implemented")
var (
ErrTemplateBuild = errors.New("template build failed")
ErrTemplateUpload = errors.New("template file upload failed")
ErrTemplate = errors.New("template error")
)