{"record":{"id":"b5fb27581ed3991a","repo":"Tencent/WeKnora","slug":"failed-to-get-file-from-ks3-w","errorCode":null,"errorMessage":"failed to get file from KS3: %w","messagePattern":"failed to get file from KS3: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/file/ks3.go","lineNumber":231,"sourceCode":"\tlogger.Infof(ctx, \"Copied KS3 object %s to %s\", srcPath, newPath)\n\treturn newPath, nil\n}\n\nfunc (s *ks3FileService) GetFile(ctx context.Context, filePath string) (io.ReadCloser, error) {\n\t_, objectKey, err := parseKS3FilePath(filePath)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif err := utils.SafeObjectKey(objectKey); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid file path: %w\", err)\n\t}\n\n\tresp, err := s.client.GetObject(&ks3s3.GetObjectInput{\n\t\tBucket: ks3aws.String(s.bucketName),\n\t\tKey:    ks3aws.String(objectKey),\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get file from KS3: %w\", err)\n\t}\n\n\treturn resp.Body, nil\n}\n\nfunc (s *ks3FileService) DeleteFile(ctx context.Context, filePath string) error {\n\t_, objectKey, err := parseKS3FilePath(filePath)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif err := utils.SafeObjectKey(objectKey); err != nil {\n\t\treturn fmt.Errorf(\"invalid file path: %w\", err)\n\t}\n\n\t_, err = s.client.DeleteObject(&ks3s3.DeleteObjectInput{\n\t\tBucket: ks3aws.String(s.bucketName),\n\t\tKey:    ks3aws.String(objectKey),\n\t})","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/file/ks3.go#L213-L249","documentation":"ks3FileService.GetFile wraps errors from the KS3 GetObject SDK call with \"failed to get file from KS3: %w\". This is a remote fetch failure: the key passed validation but the object could not be retrieved (missing, permission denied, network/endpoint issue, or bucket mismatch). The wrapped SDK error carries the underlying cause (e.g. NoSuchKey, 403, timeout).","triggerScenarios":"GetObject returns an error: object does not exist, AK/SK lacks s3:GetObject on the bucket, wrong endpoint/region, bucket deleted, network unreachable, or the ks3:// path's bucket component differs from the configured bucket.","commonSituations":"File deleted from the KS3 console while DB still references it; rotated credentials without updating config; endpoint pointing at the wrong region; bucket name changed; expired presigned lifecycle rules removed the object; firewall blocks the KS3 endpoint.","solutions":["Inspect the wrapped SDK error for the HTTP status/code: NoSuchKey/404 means the object is gone — re-upload the file or purge the stale DB record.","Verify KS3 credentials (accessKey/secretKey) have GetObject permission on the bucket, and that endpoint/region config matches the bucket's location.","Confirm the bucket in the ks3:// path equals the configured bucketName; a mismatch after config change makes GetObject target the wrong bucket.","Check network reachability to the KS3 endpoint (proxy/firewall/DNS); the client uses an SSRF-safe HTTP client that may block internal addresses.","Retry on 5xx/throttling errors — the SDK is configured with MaxRetries 3, but persistent failures indicate config problems."],"exampleFix":"// before\nrc, err := svc.GetFile(ctx, \"ks3://old-bucket/prefix/1/kb/file.pdf\") // bucket renamed\n// after\n// update STORAGE config bucket to current name, or re-save the file:\npath, err := svc.SaveFile(ctx, fileHeader, 1, \"kb\")\nrc, err := svc.GetFile(ctx, path)","handlingStrategy":"try-catch","validationCode":"// pre-check object existence if cheap\n_, err := svc.GetFileURL(ctx, path) // or HeadObject via SDK\n","typeGuard":null,"tryCatchPattern":"rc, err := svc.GetFile(ctx, path)\nif err != nil {\n\tvar awsErr error\n\tif errors.As(err, &awsErr) && strings.Contains(err.Error(), \"404\") {\n\t\t// object missing: re-upload or purge DB record\n\t} else if strings.Contains(err.Error(), \"403\") {\n\t\t// credentials/permissions problem: fix IAM/AK-SK\n\t} else {\n\t\t// network: retry with backoff\n\t}\n}","preventionTips":["Keep DB file paths in sync with actual objects (delete records when objects are removed)","Verify KS3 credentials and endpoint/region at startup via CheckKS3Connectivity","Pin the bucket name in one config source; never mix buckets in stored paths"],"tags":["ks3","object-storage","network","aws-sdk","go"],"backgroundTag":"s3-get-object-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}