{"record":{"id":"8b687356bb8309be","repo":"flipped-aurora/gin-vue-admin","slug":"function-bucket-listobjects-failed-err","errorCode":null,"errorMessage":"function bucket.ListObjects() failed, err:","messagePattern":"function bucket\\.ListObjects\\(\\) failed, err:","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/upload/aliyun_oss.go","lineNumber":142,"sourceCode":"\treturn failed, nil\n}\n\n// ListFiles 按前缀列举对象，cursor 映射为 OSS 的 marker。\nfunc (*AliyunOSS) ListFiles(ctx context.Context, prefix, cursor string, limit int) ([]FileInfo, string, bool, error) {\n\tif limit <= 0 {\n\t\tlimit = 100\n\t}\n\n\tbucket, err := NewBucket()\n\tif err != nil {\n\t\tlogger.WithCtx(ctx).Mod(\"upload\").Err(err).Error(\"function AliyunOSS.NewBucket() Failed\")\n\t\treturn nil, \"\", false, errors.New(\"function AliyunOSS.NewBucket() Failed, err:\" + err.Error())\n\t}\n\n\tresult, err := bucket.ListObjects(oss.Prefix(prefix), oss.Marker(cursor), oss.MaxKeys(limit))\n\tif err != nil {\n\t\tlogger.WithCtx(ctx).Mod(\"upload\").Err(err).Error(\"function bucket.ListObjects() failed\")\n\t\treturn nil, \"\", false, errors.New(\"function bucket.ListObjects() failed, err:\" + err.Error())\n\t}\n\n\tfiles := make([]FileInfo, 0, len(result.Objects))\n\tfor _, object := range result.Objects {\n\t\tfiles = append(files, FileInfo{\n\t\t\tKey:          object.Key,\n\t\t\tSize:         object.Size,\n\t\t\tLastModified: object.LastModified,\n\t\t})\n\t}\n\n\tnextCursor := \"\"\n\tif result.IsTruncated {\n\t\tnextCursor = result.NextMarker\n\t}\n\treturn files, nextCursor, result.IsTruncated, nil\n}\n","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/utils/upload/aliyun_oss.go#L124-L160","documentation":"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:'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify config.AliyunOSS Bucket, AccessKeyId, AccessKeySecret and BucketUrl (endpoint) are correct and the endpoint region matches the bucket","Test the credentials with ossutil ls oss://<bucket> to confirm the key can list the bucket","Grant the RAM user/role oss:ListObjects (or oss:GetObject for the prefix) on the bucket","Check network/DNS egress from the host to the endpoint; try curl https://<bucket>.<endpoint>","Read the appended err detail for the OSS error code and act on it (NoSuchBucket => fix bucket, AccessDenied => fix policy)"],"exampleFix":"// before\nBucketUrl: \"https://oss-cn-hangzhou.aliyuncs.com\" // bucket lives in oss-cn-beijing\n// after\nBucketUrl: \"https://oss-cn-beijing.aliyuncs.com\"","handlingStrategy":"try-catch","validationCode":"cfg := global.GVA_CONFIG.AliyunOSS\nif cfg.Bucket == \"\" || cfg.AccessKeyId == \"\" || cfg.AccessKeySecret == \"\" || cfg.BucketUrl == \"\" {\n    return errors.New(\"aliyun oss config incomplete: bucket/keys/endpoint required\")\n}\n// pre-flight reachability\ntype lister interface{ ListObjectsV2Page(... ) error }; _ = lister(nil)","typeGuard":"func isOssServiceError(err error) (code string, ok bool) {\n    var se smithy.APIError // or oss.ServiceError for aliyun sdk\n    if errors.As(err, &se) { return se.ErrorCode(), true }\n    return \"\", false\n}","tryCatchPattern":"files, _, _, err := ossStore.ListFiles(ctx, prefix, cursor, limit)\nif err != nil {\n    var svcErr oss.ServiceError\n    if errors.As(err, &svcErr) && svcErr.Code == \"AccessDenied\" {\n        return fmt.Errorf(\"oss list denied: check RAM policy for bucket %s: %w\", cfg.Bucket, err)\n    }\n    return fmt.Errorf(\"list files failed: %w\", err)\n}","preventionTips":["Pin endpoint region to the bucket's region in config before deploy","Grant least-privilege RAM policy including oss:ListObjects for the exact bucket/prefix","Rotate access keys with a staged rollout; verify old keys are revoked intentionally","Add a health-check that lists with MaxKeys=1 at startup to fail fast on bad config"],"tags":["oss","alibaba-cloud","aws-sdk","permissions","list-objects"],"backgroundTag":"object-storage-list-denied","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}