-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
65 lines (57 loc) · 1.65 KB
/
Copy patherrors.go
File metadata and controls
65 lines (57 loc) · 1.65 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
package engine
import (
"errors"
"fmt"
)
// ErrorCode is a stable, machine-readable engine failure category.
type ErrorCode string
const (
ErrorInvalidRequest ErrorCode = "invalid_request"
ErrorCredentialMissing ErrorCode = "credential_missing"
ErrorAuthentication ErrorCode = "authentication_failed"
ErrorCatalogUnavailable ErrorCode = "catalog_unavailable"
ErrorModelUnavailable ErrorCode = "model_unavailable"
ErrorCapabilityMismatch ErrorCode = "capability_mismatch"
ErrorContextExceeded ErrorCode = "context_exceeded"
ErrorRateLimited ErrorCode = "rate_limited"
ErrorBudgetExceeded ErrorCode = "budget_exceeded"
ErrorProviderUnavailable ErrorCode = "provider_unavailable"
ErrorCancelled ErrorCode = "cancelled"
ErrorInternal ErrorCode = "internal"
)
// Error is the typed error returned across the host boundary.
type Error struct {
Code ErrorCode
Operation string
Provider string
Model string
Message string
Retryable bool
Cause error
}
func (e *Error) Error() string {
if e == nil {
return "<nil>"
}
if e.Message != "" {
return e.Message
}
if e.Operation != "" {
return fmt.Sprintf("eyrie engine: %s failed", e.Operation)
}
return "eyrie engine error"
}
func (e *Error) Unwrap() error {
if e == nil {
return nil
}
return e.Cause
}
// IsCode reports whether err or an error in its chain has the supplied code.
func IsCode(err error, code ErrorCode) bool {
var target *Error
return errors.As(err, &target) && target.Code == code
}
func invalid(operation, message string) error {
return &Error{Code: ErrorInvalidRequest, Operation: operation, Message: message}
}