-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
116 lines (95 loc) · 3.05 KB
/
errors.go
File metadata and controls
116 lines (95 loc) · 3.05 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
package s3
// ErrorCode represents structured error codes for S3 operations
type ErrorCode string
const (
// ErrBucketNotFound indicates the requested bucket doesn't exist
ErrBucketNotFound ErrorCode = "BUCKET_NOT_FOUND"
// ErrFileNotFound indicates the requested file doesn't exist
ErrFileNotFound ErrorCode = "FILE_NOT_FOUND"
// ErrInvalidConfig indicates invalid configuration
ErrInvalidConfig ErrorCode = "INVALID_CONFIG"
// ErrS3Operation indicates an S3 operation failed
ErrS3Operation ErrorCode = "S3_OPERATION_FAILED"
// ErrPermissionDenied indicates insufficient permissions
ErrPermissionDenied ErrorCode = "PERMISSION_DENIED"
// ErrInvalidPathname indicates invalid file path
ErrInvalidPathname ErrorCode = "INVALID_PATHNAME"
// ErrBucketAlreadyExists indicates bucket is already registered
ErrBucketAlreadyExists ErrorCode = "BUCKET_ALREADY_EXISTS"
// ErrInvalidVisibility indicates invalid visibility value
ErrInvalidVisibility ErrorCode = "INVALID_VISIBILITY"
// ErrOperationTimeout indicates operation exceeded timeout
ErrOperationTimeout ErrorCode = "OPERATION_TIMEOUT"
)
// S3Error represents a structured error returned to PHP
type S3Error struct {
// Code is the error code
Code ErrorCode `json:"code"`
// Message is the human-readable error message
Message string `json:"message"`
// Details contains additional error context (optional)
Details string `json:"details,omitempty"`
}
// Error implements the error interface
func (e *S3Error) Error() string {
if e.Details != "" {
return string(e.Code) + ": " + e.Message + " (" + e.Details + ")"
}
return string(e.Code) + ": " + e.Message
}
// NewS3Error creates a new S3Error
func NewS3Error(code ErrorCode, message string, details string) *S3Error {
return &S3Error{
Code: code,
Message: message,
Details: details,
}
}
// NewBucketNotFoundError creates a bucket not found error
func NewBucketNotFoundError(bucketName string) *S3Error {
return NewS3Error(
ErrBucketNotFound,
"Bucket not found",
"bucket: "+bucketName,
)
}
// NewFileNotFoundError creates a file not found error
func NewFileNotFoundError(pathname string) *S3Error {
return NewS3Error(
ErrFileNotFound,
"File not found",
"pathname: "+pathname,
)
}
// NewInvalidConfigError creates an invalid config error
func NewInvalidConfigError(reason string) *S3Error {
return NewS3Error(
ErrInvalidConfig,
"Invalid configuration",
reason,
)
}
// NewS3OperationError creates an S3 operation error
func NewS3OperationError(operation string, err error) *S3Error {
return NewS3Error(
ErrS3Operation,
"S3 operation failed: "+operation,
err.Error(),
)
}
// NewPermissionDeniedError creates a permission denied error
func NewPermissionDeniedError(operation string) *S3Error {
return NewS3Error(
ErrPermissionDenied,
"Permission denied",
"operation: "+operation,
)
}
// NewInvalidPathnameError creates an invalid pathname error
func NewInvalidPathnameError(pathname string, reason string) *S3Error {
return NewS3Error(
ErrInvalidPathname,
"Invalid pathname",
"pathname: "+pathname+", reason: "+reason,
)
}