-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.go
More file actions
111 lines (91 loc) · 3.15 KB
/
errors.go
File metadata and controls
111 lines (91 loc) · 3.15 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
// Package sindoq provides a unified SDK for code execution across multiple isolated environments.
package sindoq
import (
"errors"
"fmt"
)
// Sentinel errors for common conditions.
var (
// ErrSandboxNotFound indicates sandbox doesn't exist.
ErrSandboxNotFound = errors.New("sandbox not found")
// ErrSandboxStopped indicates sandbox is not running.
ErrSandboxStopped = errors.New("sandbox is stopped")
// ErrExecutionTimeout indicates execution exceeded timeout.
ErrExecutionTimeout = errors.New("execution timeout")
// ErrProviderUnavailable indicates provider is not accessible.
ErrProviderUnavailable = errors.New("provider unavailable")
// ErrLanguageNotSupported indicates language isn't supported.
ErrLanguageNotSupported = errors.New("language not supported")
// ErrLanguageDetectionFailed indicates detection couldn't determine language.
ErrLanguageDetectionFailed = errors.New("language detection failed")
// ErrResourceExhausted indicates resource limits exceeded.
ErrResourceExhausted = errors.New("resource exhausted")
// ErrPermissionDenied indicates operation not permitted.
ErrPermissionDenied = errors.New("permission denied")
// ErrInvalidConfiguration indicates invalid configuration.
ErrInvalidConfiguration = errors.New("invalid configuration")
// ErrProviderNotRegistered indicates provider is not registered.
ErrProviderNotRegistered = errors.New("provider not registered")
)
// SandboxError wraps errors with context.
type SandboxError struct {
Op string // Operation that failed
Provider string // Provider involved
SandboxID string // Sandbox ID if known
Err error // Underlying error
}
// Error implements the error interface.
func (e *SandboxError) Error() string {
if e.SandboxID != "" {
return fmt.Sprintf("%s [%s/%s]: %v", e.Op, e.Provider, e.SandboxID, e.Err)
}
if e.Provider != "" {
return fmt.Sprintf("%s [%s]: %v", e.Op, e.Provider, e.Err)
}
return fmt.Sprintf("%s: %v", e.Op, e.Err)
}
// Unwrap returns the underlying error.
func (e *SandboxError) Unwrap() error {
return e.Err
}
// Is supports errors.Is for comparison.
func (e *SandboxError) Is(target error) bool {
return errors.Is(e.Err, target)
}
// NewError creates a SandboxError.
func NewError(op, provider, sandboxID string, err error) *SandboxError {
return &SandboxError{
Op: op,
Provider: provider,
SandboxID: sandboxID,
Err: err,
}
}
// ExecutionError contains details about execution failures.
type ExecutionError struct {
ExitCode int
Stdout string
Stderr string
Err error
}
// Error implements the error interface.
func (e *ExecutionError) Error() string {
if e.Stderr != "" {
return fmt.Sprintf("execution failed (exit code %d): %v\nstderr: %s",
e.ExitCode, e.Err, e.Stderr)
}
return fmt.Sprintf("execution failed (exit code %d): %v", e.ExitCode, e.Err)
}
// Unwrap returns the underlying error.
func (e *ExecutionError) Unwrap() error {
return e.Err
}
// NewExecutionError creates an ExecutionError.
func NewExecutionError(exitCode int, stdout, stderr string, err error) *ExecutionError {
return &ExecutionError{
ExitCode: exitCode,
Stdout: stdout,
Stderr: stderr,
Err: err,
}
}