flipped-aurora/gin-vue-admin · error

function bucket.ListObjects() failed, err:

Error message

function bucket.ListObjects() failed, err:

What it means

Wraps the error returned by the AWS-SDK-style bucket.ListObjects() call of the Alibaba OSS SDK (aliyun-oss-go-sdk) during paginated listing. The SDK surfaces any HTTP, auth, bucket-permission or networking problem as a Go error from this call, which the wrapper re-wraps with context so the upload abstraction's ListFiles() caller sees a uniform message. The original OSS error string (including OSS error codes like NoSuchBucket or AccessDenied) is appended after 'err:'.

Source

Thrown at server/utils/upload/aliyun_oss.go:142

	return failed, nil
}

// ListFiles 按前缀列举对象,cursor 映射为 OSS 的 marker。
func (*AliyunOSS) ListFiles(ctx context.Context, prefix, cursor string, limit int) ([]FileInfo, string, bool, error) {
	if limit <= 0 {
		limit = 100
	}

	bucket, err := NewBucket()
	if err != nil {
		logger.WithCtx(ctx).Mod("upload").Err(err).Error("function AliyunOSS.NewBucket() Failed")
		return nil, "", false, errors.New("function AliyunOSS.NewBucket() Failed, err:" + err.Error())
	}

	result, err := bucket.ListObjects(oss.Prefix(prefix), oss.Marker(cursor), oss.MaxKeys(limit))
	if err != nil {
		logger.WithCtx(ctx).Mod("upload").Err(err).Error("function bucket.ListObjects() failed")
		return nil, "", false, errors.New("function bucket.ListObjects() failed, err:" + err.Error())
	}

	files := make([]FileInfo, 0, len(result.Objects))
	for _, object := range result.Objects {
		files = append(files, FileInfo{
			Key:          object.Key,
			Size:         object.Size,
			LastModified: object.LastModified,
		})
	}

	nextCursor := ""
	if result.IsTruncated {
		nextCursor = result.NextMarker
	}
	return files, nextCursor, result.IsTruncated, nil
}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Verify config.AliyunOSS Bucket, AccessKeyId, AccessKeySecret and BucketUrl (endpoint) are correct and the endpoint region matches the bucket
  2. Test the credentials with ossutil ls oss://<bucket> to confirm the key can list the bucket
  3. Grant the RAM user/role oss:ListObjects (or oss:GetObject for the prefix) on the bucket
  4. Check network/DNS egress from the host to the endpoint; try curl https://<bucket>.<endpoint>
  5. Read the appended err detail for the OSS error code and act on it (NoSuchBucket => fix bucket, AccessDenied => fix policy)

Example fix

// before
BucketUrl: "https://oss-cn-hangzhou.aliyuncs.com" // bucket lives in oss-cn-beijing
// after
BucketUrl: "https://oss-cn-beijing.aliyuncs.com"
Defensive patterns

Strategy: try-catch

Validate before calling

cfg := global.GVA_CONFIG.AliyunOSS
if cfg.Bucket == "" || cfg.AccessKeyId == "" || cfg.AccessKeySecret == "" || cfg.BucketUrl == "" {
    return errors.New("aliyun oss config incomplete: bucket/keys/endpoint required")
}
// pre-flight reachability
type lister interface{ ListObjectsV2Page(... ) error }; _ = lister(nil)

Type guard

func isOssServiceError(err error) (code string, ok bool) {
    var se smithy.APIError // or oss.ServiceError for aliyun sdk
    if errors.As(err, &se) { return se.ErrorCode(), true }
    return "", false
}

Try / catch

files, _, _, err := ossStore.ListFiles(ctx, prefix, cursor, limit)
if err != nil {
    var svcErr oss.ServiceError
    if errors.As(err, &svcErr) && svcErr.Code == "AccessDenied" {
        return fmt.Errorf("oss list denied: check RAM policy for bucket %s: %w", cfg.Bucket, err)
    }
    return fmt.Errorf("list files failed: %w", err)
}

Prevention

When it happens

Trigger: Calling ListFiles on aliyun-oss when: the bucket name in config.AliyunOSS.Bucket does not exist, the AccessKeyId/Secret is wrong or revoked, the credentials lack oss:ListObjects permission, the endpoint is unreachable/misconfigured, or a network timeout occurs while paging with prefix/marker/limit.

Common situations: Switching OSS regions without updating BucketUrl endpoint; using a RAM user without read permission on the bucket; typo in bucket name; expired or rotated access keys still deployed; private-network/DNS issues in containers reaching the public endpoint.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/8b687356bb8309be. Report an issue: GitHub.