Skip to content

Commit a775d0d

Browse files
authored
Simplify error messages for object storage (EA) (#266)
Drop redundant "received response code NNN:" prefix from `storageErrorMessage` and remove extra error wrapping in object commands to reduce noise in user-facing output. e.g. "failed to download object: failed to download file: received response code 404: object not found" becomes "failed to download file: object not found"
1 parent 535ff10 commit a775d0d

5 files changed

Lines changed: 30 additions & 32 deletions

File tree

cmd/objectdelete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func deleteObject(cmd *cobra.Command, input ObjectDeleteInput) (*storage.DeleteR
9999

100100
result, err := svc.Delete(ctx, input.Key)
101101
if err != nil {
102-
return nil, fmt.Errorf("failed to delete object: %w", err)
102+
return nil, err
103103
}
104104

105105
return result, nil

cmd/objectget.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func downloadObjectToFile(cmd *cobra.Command, input ObjectGetInput) (*storage.Do
105105
if err != nil {
106106
// Clean up partial file on error
107107
os.Remove(input.FilePath)
108-
return nil, fmt.Errorf("failed to download object: %w", err)
108+
return nil, err
109109
}
110110

111111
result.LocalPath = input.FilePath
@@ -127,7 +127,7 @@ func downloadObjectToStdout(cmd *cobra.Command, input ObjectGetInput) error {
127127

128128
_, err = svc.Download(ctx, input.Key, os.Stdout)
129129
if err != nil {
130-
return fmt.Errorf("failed to download object: %w", err)
130+
return err
131131
}
132132

133133
return nil

cmd/objectput.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func uploadObject(cmd *cobra.Command, input ObjectPutInput) (*storage.UploadResu
9393

9494
result, err := svc.Upload(ctx, input.Key, input.FilePath)
9595
if err != nil {
96-
return nil, fmt.Errorf("failed to upload object: %w", err)
96+
return nil, err
9797
}
9898

9999
return result, nil

pkg/storage/repo.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,22 @@ func (r *Repo) DownloadFromPresignedURL(ctx context.Context, presignedURL string
179179
}
180180

181181
func storageErrorMessage(statusCode int) string {
182-
var message string
183182
switch statusCode {
184183
case 400:
185-
message = "bad request"
184+
return "bad request"
186185
case 401, 403:
187-
message = "access denied"
186+
return "access denied"
188187
case 404:
189-
message = "object not found"
188+
return "object not found"
190189
case 409:
191-
message = "conflict"
190+
return "conflict"
192191
case 413:
193-
message = "object too large"
192+
return "object too large"
194193
case 429:
195-
message = "rate limited, please try again later"
194+
return "rate limited, please try again later"
196195
case 500, 502, 503, 504:
197-
message = "storage service temporarily unavailable"
196+
return "storage service temporarily unavailable"
198197
default:
199-
message = "unexpected error"
198+
return fmt.Sprintf("unexpected error (HTTP %d)", statusCode)
200199
}
201-
return fmt.Sprintf("received response code %d: %s", statusCode, message)
202200
}

pkg/storage/repo_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,62 +20,62 @@ func TestStorageErrorMessage(t *testing.T) {
2020
{
2121
name: "400 bad request",
2222
statusCode: 400,
23-
want: "received response code 400: bad request",
23+
want: "bad request",
2424
},
2525
{
2626
name: "401 unauthorized",
2727
statusCode: 401,
28-
want: "received response code 401: access denied",
28+
want: "access denied",
2929
},
3030
{
3131
name: "403 forbidden",
3232
statusCode: 403,
33-
want: "received response code 403: access denied",
33+
want: "access denied",
3434
},
3535
{
3636
name: "404 not found",
3737
statusCode: 404,
38-
want: "received response code 404: object not found",
38+
want: "object not found",
3939
},
4040
{
4141
name: "409 conflict",
4242
statusCode: 409,
43-
want: "received response code 409: conflict",
43+
want: "conflict",
4444
},
4545
{
4646
name: "413 payload too large",
4747
statusCode: 413,
48-
want: "received response code 413: object too large",
48+
want: "object too large",
4949
},
5050
{
5151
name: "429 too many requests",
5252
statusCode: 429,
53-
want: "received response code 429: rate limited, please try again later",
53+
want: "rate limited, please try again later",
5454
},
5555
{
5656
name: "500 internal server error",
5757
statusCode: 500,
58-
want: "received response code 500: storage service temporarily unavailable",
58+
want: "storage service temporarily unavailable",
5959
},
6060
{
6161
name: "502 bad gateway",
6262
statusCode: 502,
63-
want: "received response code 502: storage service temporarily unavailable",
63+
want: "storage service temporarily unavailable",
6464
},
6565
{
6666
name: "503 service unavailable",
6767
statusCode: 503,
68-
want: "received response code 503: storage service temporarily unavailable",
68+
want: "storage service temporarily unavailable",
6969
},
7070
{
7171
name: "504 gateway timeout",
7272
statusCode: 504,
73-
want: "received response code 504: storage service temporarily unavailable",
73+
want: "storage service temporarily unavailable",
7474
},
7575
{
7676
name: "unknown status code",
7777
statusCode: 418,
78-
want: "received response code 418: unexpected error",
78+
want: "unexpected error (HTTP 418)",
7979
},
8080
}
8181

@@ -100,22 +100,22 @@ func TestDownloadFromPresignedURL_StorageErrors(t *testing.T) {
100100
statusCode: 404,
101101
responseBody: `<?xml version="1.0" encoding="UTF-8"?>
102102
<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>tea-d3tc3fuuk2gs73d0paug/foo/bar/test.txt</Key><RequestId>95N55HR7H0QBF3X9</RequestId><HostId>QfLXA55SGkqZ6VEKV97lgMjiFNWRFhpTj29FAylq2SOh2LJFMyvHuRdUjDu1IaZ/NmQR0znt4/0=</HostId></Error>`,
103-
wantErrContain: []string{"received response code 404", "object not found"},
103+
wantErrContain: []string{"object not found"},
104104
wantErrExclude: []string{"NoSuchKey", "tea-d3tc3fuuk2gs73d0paug", "RequestId", "HostId"},
105105
},
106106
{
107107
name: "403 with GCS error",
108108
statusCode: 403,
109109
responseBody: `<?xml version='1.0' encoding='UTF-8'?>
110110
<Error><Code>AccessDenied</Code><Message>Access denied.</Message><Details>render-objects-bucket/some/path</Details></Error>`,
111-
wantErrContain: []string{"received response code 403", "access denied"},
111+
wantErrContain: []string{"access denied"},
112112
wantErrExclude: []string{"render-objects-bucket", "AccessDenied", "Details"},
113113
},
114114
{
115115
name: "500 server error",
116116
statusCode: 500,
117117
responseBody: `Internal Server Error: connection to storage backend failed`,
118-
wantErrContain: []string{"received response code 500", "storage service temporarily unavailable"},
118+
wantErrContain: []string{"storage service temporarily unavailable"},
119119
wantErrExclude: []string{"Internal Server Error", "storage backend"},
120120
},
121121
}
@@ -163,22 +163,22 @@ func TestUploadToPresignedURL_StorageErrors(t *testing.T) {
163163
statusCode: 403,
164164
responseBody: `<?xml version="1.0" encoding="UTF-8"?>
165165
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>ABC123</RequestId><HostId>xyz789</HostId></Error>`,
166-
wantErrContain: []string{"received response code 403", "access denied"},
166+
wantErrContain: []string{"access denied"},
167167
wantErrExclude: []string{"AccessDenied", "RequestId", "HostId", "ABC123", "xyz789"},
168168
},
169169
{
170170
name: "413 payload too large",
171171
statusCode: 413,
172172
responseBody: `<?xml version="1.0" encoding="UTF-8"?>
173173
<Error><Code>EntityTooLarge</Code><Message>Your proposed upload exceeds the maximum allowed size</Message><MaxSizeAllowed>5368709120</MaxSizeAllowed></Error>`,
174-
wantErrContain: []string{"received response code 413", "object too large"},
174+
wantErrContain: []string{"object too large"},
175175
wantErrExclude: []string{"EntityTooLarge", "MaxSizeAllowed", "5368709120"},
176176
},
177177
{
178178
name: "502 bad gateway",
179179
statusCode: 502,
180180
responseBody: `Bad Gateway: upstream storage unavailable`,
181-
wantErrContain: []string{"received response code 502", "storage service temporarily unavailable"},
181+
wantErrContain: []string{"storage service temporarily unavailable"},
182182
wantErrExclude: []string{"Bad Gateway", "upstream"},
183183
},
184184
}

0 commit comments

Comments
 (0)