Skip to content

Commit 8b71881

Browse files
authored
Merge pull request #22 from nvaatstra/handle-list-errors
S3: Handle errors returned by MinIO Client ListObjects
2 parents 3704775 + 4909c89 commit 8b71881

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

backends/s3/s3.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
"time"
1616

1717
"github.com/PowerDNS/go-tlsconfig"
18-
"github.com/minio/minio-go/v7"
1918
"github.com/go-logr/logr"
19+
"github.com/minio/minio-go/v7"
2020
"github.com/minio/minio-go/v7/pkg/credentials"
2121

2222
"github.com/PowerDNS/simpleblob"
@@ -117,7 +117,7 @@ func (b *Backend) List(ctx context.Context, prefix string) (simpleblob.BlobList,
117117
m, err := b.Load(ctx, UpdateMarkerFilename)
118118
exists := !errors.Is(err, os.ErrNotExist)
119119
if err != nil && exists {
120-
return nil, err
120+
return nil, err
121121
}
122122
upstreamMarker := string(m)
123123

@@ -155,6 +155,12 @@ func (b *Backend) doList(ctx context.Context, prefix string) (simpleblob.BlobLis
155155
Recursive: false,
156156
})
157157
for obj := range objCh {
158+
// Handle error returned by MinIO client
159+
if err := convertMinioError(obj.Err); err != nil {
160+
metricCallErrors.WithLabelValues("list").Inc()
161+
return nil, err
162+
}
163+
158164
metricCalls.WithLabelValues("list").Inc()
159165
metricLastCallTimestamp.WithLabelValues("list").SetToCurrentTime()
160166
if obj.Key == UpdateMarkerFilename {

test.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ if [ -z "$SIMPLEBLOB_TEST_S3_CONFIG" ]; then
2424

2525
# Fetch minio if not found
2626
if ! command -v minio >/dev/null; then
27-
source <(go env)
2827
dst="$GOBIN/minio"
29-
curl -v -o "$dst" "https://dl.min.io/server/minio/release/$GOOS-$GOARCH/minio"
28+
curl -v -o "$dst" "https://dl.min.io/server/minio/release/$(go env GOOS)-$(go env GOARCH)/minio"
3029
chmod u+x "$dst"
3130
fi
3231

tester/tester.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ func DoBackendTests(t *testing.T, b simpleblob.Interface) {
4646
assert.NoError(t, err)
4747
assert.Equal(t, ls.Names(), []string{"bar-1", "bar-2"}) // sorted
4848

49+
// List with non-existing prefix
50+
ls, err = b.List(ctx, "does-not-exist-")
51+
assert.NoError(t, err)
52+
assert.Nil(t, ls.Names())
53+
4954
// Load
5055
data, err := b.Load(ctx, "foo-1")
5156
assert.NoError(t, err)

0 commit comments

Comments
 (0)