Tencent/WeKnora · error
failed to get file from KS3: %w
Error message
failed to get file from KS3: %w
What it means
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).
Source
Thrown at internal/application/service/file/ks3.go:231
logger.Infof(ctx, "Copied KS3 object %s to %s", srcPath, newPath)
return newPath, nil
}
func (s *ks3FileService) GetFile(ctx context.Context, filePath string) (io.ReadCloser, error) {
_, objectKey, err := parseKS3FilePath(filePath)
if err != nil {
return nil, err
}
if err := utils.SafeObjectKey(objectKey); err != nil {
return nil, fmt.Errorf("invalid file path: %w", err)
}
resp, err := s.client.GetObject(&ks3s3.GetObjectInput{
Bucket: ks3aws.String(s.bucketName),
Key: ks3aws.String(objectKey),
})
if err != nil {
return nil, fmt.Errorf("failed to get file from KS3: %w", err)
}
return resp.Body, nil
}
func (s *ks3FileService) DeleteFile(ctx context.Context, filePath string) error {
_, objectKey, err := parseKS3FilePath(filePath)
if err != nil {
return err
}
if err := utils.SafeObjectKey(objectKey); err != nil {
return fmt.Errorf("invalid file path: %w", err)
}
_, err = s.client.DeleteObject(&ks3s3.DeleteObjectInput{
Bucket: ks3aws.String(s.bucketName),
Key: ks3aws.String(objectKey),
})View on GitHub (pinned to 988cbb0330)
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.
Example fix
// before rc, err := svc.GetFile(ctx, "ks3://old-bucket/prefix/1/kb/file.pdf") // bucket renamed // after // update STORAGE config bucket to current name, or re-save the file: path, err := svc.SaveFile(ctx, fileHeader, 1, "kb") rc, err := svc.GetFile(ctx, path)
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check object existence if cheap _, err := svc.GetFileURL(ctx, path) // or HeadObject via SDK
Try / catch
rc, err := svc.GetFile(ctx, path)
if err != nil {
var awsErr error
if errors.As(err, &awsErr) && strings.Contains(err.Error(), "404") {
// object missing: re-upload or purge DB record
} else if strings.Contains(err.Error(), "403") {
// credentials/permissions problem: fix IAM/AK-SK
} else {
// network: retry with backoff
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to delete file from KS3: %w
- invalid file path: %w
- failed to generate KS3 presigned URL: %w
- rerank call failed: %w
- failed to do bulk: %w
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/b5fb27581ed3991a.
Report an issue: GitHub.