{"record":{"id":"46103b67f29e8139","repo":"flipped-aurora/gin-vue-admin","slug":"function-bucket-isobjectexist-failed-err","errorCode":null,"errorMessage":"function bucket.IsObjectExist() failed, err:","messagePattern":"function bucket\\.IsObjectExist\\(\\) failed, err:","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/upload/aliyun_oss.go","lineNumber":89,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn bucket, nil\n}\n\n// Exists 检查对象是否存在，\"不存在\"统一降级为 (false, nil)。\nfunc (*AliyunOSS) Exists(ctx context.Context, key string) (bool, error) {\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 false, errors.New(\"function AliyunOSS.NewBucket() Failed, err:\" + err.Error())\n\t}\n\n\texist, err := bucket.IsObjectExist(key)\n\tif err != nil {\n\t\tlogger.WithCtx(ctx).Mod(\"upload\").Err(err).Error(\"function bucket.IsObjectExist() failed\")\n\t\treturn false, errors.New(\"function bucket.IsObjectExist() failed, err:\" + err.Error())\n\t}\n\treturn exist, nil\n}\n\n// DeleteFiles 批量删除对象，对比入参与已删除列表，未删的收集为 DeleteFailure。\nfunc (*AliyunOSS) DeleteFiles(ctx context.Context, keys []string) ([]DeleteFailure, error) {\n\tif len(keys) == 0 {\n\t\treturn nil, nil\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, errors.New(\"function AliyunOSS.NewBucket() Failed, err:\" + err.Error())\n\t}\n\n\tresult, err := bucket.DeleteObjects(keys)\n\tif err != nil {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/utils/upload/aliyun_oss.go#L71-L107","documentation":"Returned by AliyunOSS.Exists (server/utils/upload/aliyun_oss.go:89) when bucket.IsObjectExist(key) fails. IsObjectExist issues a HeadObject request against the OSS bucket via the aliyun-oss-go-sdk; any transport error, authentication failure, permission denial, or bucket mismatch is wrapped here. Note that a nonexistent object is NOT an error — it returns (false, nil); this error means the check itself could not be performed.","triggerScenarios":"Calling Exists with an invalid/expired AccessKeyId or AccessKeySecret, wrong Endpoint (region mismatch or non-standard endpoint format), a BucketName that doesn't exist or belongs to another account, network/DNS failure reaching the endpoint, or missing oss:GetObject/HeadObject permission (AccessDenied 403).","commonSituations":"Misconfigured config.AliyunOSS values (typo in endpoint like missing https:// or wrong region), RAM user lacking read permission on the bucket, key rotated or revoked in Aliyun console, bucket deleted/renamed, offline or restricted-network deployment (e.g. container without egress to oss-*.aliyuncs.com).","solutions":["Verify config.AliyunOSS: Endpoint (e.g. oss-cn-hangzhou.aliyuncs.com), AccessKeyId/Secret, BucketName all correct and the bucket exists in that region","Test credentials with `ossutil ls` or a minimal oss.New + bucket.IsObjectExist snippet to see the raw OSS error code","Check RAM permissions: grant the user oss:GetObject on the bucket/resource arn","Check network reachability/DNS to the endpoint from the server (curl the endpoint URL)","Inspect the wrapped err text — OSS SDK errors carry ServiceError codes like SignatureDoesNotMatch or AccessDenied that pinpoint the cause"],"exampleFix":"// before\nexist, err := bucket.IsObjectExist(key)\nif err != nil {\n\treturn false, errors.New(\"function bucket.IsObjectExist() failed, err:\" + err.Error())\n}\n// after: distinguish auth/config failure from transient network issues\nexist, err := bucket.IsObjectExist(key)\nif err != nil {\n\tvar serr oss.ServiceError\n\tif errors.As(err, &serr) && serr.StatusCode == 403 {\n\t\tlogger.WithCtx(ctx).Mod(\"upload\").Error(\"OSS AccessDenied: check AK/permissions\")\n\t}\n\treturn false, fmt.Errorf(\"function bucket.IsObjectExist() failed: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"cfg := global.GVA_CONFIG.AliyunOSS\nif cfg.Endpoint == \"\" || cfg.AccessKeyId == \"\" || cfg.BucketName == \"\" {\n\treturn errors.New(\"aliyun-oss config incomplete\")\n}","typeGuard":"func isOSSServiceError(err error) (oss.ServiceError, bool) {\n\tvar se oss.ServiceError\n\tif errors.As(err, &se) {\n\t\treturn se, true\n\t}\n\treturn oss.ServiceError{}, false\n}","tryCatchPattern":"exist, err := uploadSvc.Exists(ctx, key)\nif err != nil {\n\tif se, ok := isOSSServiceError(err); ok {\n\t\tlogger.Errorf(\"OSS check failed code=%s status=%d\", se.Code, se.StatusCode)\n\t}\n\t// decide: treat as 'unknown' and skip, or abort the operation\n\treturn fmt.Errorf(\"object existence check unavailable: %w\", err)\n}","preventionTips":["Validate the AliyunOSS config block at application startup with a real NewBucket round-trip","Grant the RAM user explicit oss:GetObject/oss:ListObjects read permissions","Pin the endpoint to the bucket's actual region; never mix regions","Log the raw wrapped OSS error code (ServiceError.Code) to distinguish auth vs network vs permission"],"tags":["oss","aliyun","storage","config","network"],"backgroundTag":"oss-head-object-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}