Tencent/WeKnora · error
failed to get file from OBS: %w
Error message
failed to get file from OBS: %w
What it means
Storage error in obsFileService.GetFile: the S3-compatible GetObject request for the parsed OBS object key failed. The %w wraps the AWS SDK error so the real cause (missing object, credentials, endpoint) stays inspectable; invalid obs:// paths fail earlier in parseObsFilePath.
Source
Thrown at internal/application/service/file/obs.go:202
prefix := s.getPrifix()
if s.proxyDomain != "" {
return fmt.Sprintf("%s%s", prefix, objectKey), nil
}
return fmt.Sprintf("%s%s/%s", prefix, s.bucketName, objectKey), nil
}
func (s *obsFileService) GetFile(ctx context.Context, filePath string) (io.ReadCloser, error) {
objectKey, err := s.parseObsFilePath(filePath)
if err != nil {
return nil, err
}
output, err := s.client.GetObject(ctx, &s3.GetObjectInput{
Bucket: aws.String(s.bucketName),
Key: aws.String(objectKey),
})
if err != nil {
return nil, fmt.Errorf("failed to get file from OBS: %w", err)
}
return output.Body, nil
}
func (s *obsFileService) DeleteFile(ctx context.Context, filePath string) error {
objectKey, err := s.parseObsFilePath(filePath)
if err != nil {
return err
}
_, err = s.client.DeleteObject(ctx, &s3.DeleteObjectInput{
Bucket: aws.String(s.bucketName),
Key: aws.String(objectKey),
})
if err != nil {
return fmt.Errorf("failed to delete file from OBS: %w", err)
}View on GitHub (pinned to 988cbb0330)
Solutions
- Unwrap and check for NoSuchKey/404 — treat as 'file not found' and return 404 to the caller
- Verify the stored filePath parses to an existing key (list or HeadObject the bucket)
- Check bucketName/endpoint/region config matches where the file was uploaded
- Verify credentials have s3:GetObject permission on the bucket/prefix
Example fix
// before
if err != nil { return nil, fmt.Errorf("failed to get file from OBS: %w", err) }
// after
var nf *types.NotFound
if err != nil {
if errors.As(err, &nf) || strings.Contains(err.Error(), "NoSuchKey") {
return nil, ErrFileNotFound
}
return nil, fmt.Errorf("failed to get file from OBS: %w", err)
} Defensive patterns
Strategy: try-catch
Try / catch
r, err := svc.GetFile(ctx, p)
if err != nil {
if strings.Contains(err.Error(), "NoSuchKey") || strings.Contains(err.Error(), "NotFound") {
http.NotFound(w, r)
return
}
http.Error(w, "storage error", http.StatusInternalServerError)
} Prevention
- Treat missing-key as a normal 404 path, not an internal error
- Verify stored paths exist lazily and clean dangling DB rows
- Check GetObject permission on the app's credentials
When it happens
Trigger: Calling GetFile with a filePath whose parsed objectKey does not exist in the bucket (deleted or never uploaded), wrong bucket/region config, or no s3:GetObject permission.
Common situations: Stale DB path pointing to a deleted object; bucket renamed; credentials lacking read permission; typo in proxyDomain config changing how paths parse; object in a different region than the client endpoint.
Related errors
- failed to upload file to OBS: %w
- failed to copy file in OBS: %w
- failed to delete file from OBS: %w
- failed to upload bytes to OBS: %w
- failed to check bucket: %w
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/c3749ad7baf69f13.
Report an issue: GitHub.