flipped-aurora/gin-vue-admin · error
function client.Bucket.Get() failed, err:
Error message
function client.Bucket.Get() failed, err:
What it means
Wraps an error from the COS SDK's client.Bucket.Get() in TencentCOS.ListFiles(). Bucket.Get lists bucket contents with prefix/marker pagination; any request-level failure surfaces here.
Source
Thrown at server/utils/upload/tencent_cos.go:109
}
return failed, nil
}
// ListFiles 按前缀列举对象,marker 分页:Marker=cursor,NextMarker→nextCursor,IsTruncated→hasMore。
func (*TencentCOS) ListFiles(ctx context.Context, prefix, cursor string, limit int) (files []FileInfo, nextCursor string, hasMore bool, err error) {
if limit <= 0 {
limit = 100
}
client := NewClient()
res, _, err := client.Bucket.Get(ctx, &cos.BucketGetOptions{
Prefix: prefix,
Marker: cursor,
MaxKeys: limit,
})
if err != nil {
logger.WithCtx(ctx).Mod("upload").Err(err).Error("function client.Bucket.Get() failed")
return nil, "", false, errors.New("function client.Bucket.Get() failed, err:" + err.Error())
}
if res != nil {
for _, c := range res.Contents {
files = append(files, FileInfo{
Key: c.Key,
Size: c.Size,
LastModified: parseCOSLastModified(c.LastModified),
})
}
hasMore = res.IsTruncated
if hasMore && res.NextMarker != "" {
nextCursor = res.NextMarker
} else if hasMore && len(files) > 0 {
// COS 未返回 NextMarker 时回退用最后一条 key 作为下次 marker
nextCursor = files[len(files)-1].Key
}
}View on GitHub (pinned to 3136500ef3)
Solutions
- Check the wrapped err suffix for the COS error code
- Grant cos:GetBucket permission to the API key in CAM
- Verify Bucket/Region configuration matches the target bucket
- Restart listing with an empty cursor if the marker was rejected; retry transient errors
Example fix
// before
files, marker, hasMore, err := cos.ListFiles(ctx, "", staleCursor, 10)
// after
if err != nil && strings.Contains(err.Error(), "InvalidArgument") {
files, marker, hasMore, err = cos.ListFiles(ctx, "", "", 10)
} Defensive patterns
Strategy: try-catch
Validate before calling
if limit <= 0 || limit > 1000 {
limit = 100 // COS Bucket.Get MaxKeys bounds
} Try / catch
files, marker, hasMore, err := cos.ListFiles(ctx, prefix, cursor, limit)
if err != nil {
if strings.Contains(err.Error(), "AccessDenied") {
// grant cos:GetBucket
}
return nil, "", false, fmt.Errorf("list bucket failed: %w", err)
} Prevention
- Grant cos:GetBucket (ListObjects) permission
- Use fresh markers returned by each page
- Validate bucket/region config before listing
When it happens
Trigger: Calling ListFiles(ctx, prefix, cursor, limit) when Bucket.Get fails: invalid marker, auth failure, wrong region/bucket, or network error.
Common situations: Expired credentials, CAM policy missing cos:GetBucket (ListObjects), stale continuation marker, bucket region endpoint unreachable.
Related errors
- function bucketManager.ListFiles() failed, err:
- function client.Object.Put() failed, err:
- function bucketManager.Delete() failed, err:
- function client.Object.Head() failed, err:
- function client.Object.DeleteMulti() failed, err:
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/e0322108440c0a4e.
Report an issue: GitHub.