Tencent/WeKnora · error
failed to get file from S3: %w
Error message
failed to get file from S3: %w
What it means
GetFile wraps any error returned by the AWS S3 GetObject call with 'failed to get file from S3'. It means the object could not be read from the bucket — either the key does not exist, credentials/permissions are insufficient, or the S3 call failed at the network level. The underlying S3 error is preserved via %w for errors.Is/As inspection.
Source
Thrown at internal/application/service/file/s3.go:268
return "", fmt.Errorf("failed to upload file to S3: %w", err)
}
return fmt.Sprintf("s3://%s/%s", s.bucketName, objectName), nil
}
// GetFile gets a file from S3
func (s *s3FileService) GetFile(ctx context.Context, filePath string) (io.ReadCloser, error) {
objectName, err := s.parseS3FilePath(filePath)
if err != nil {
return nil, err
}
resp, err := s.client.GetObject(ctx, &s3.GetObjectInput{
Bucket: aws.String(s.bucketName),
Key: aws.String(objectName),
})
if err != nil {
return nil, fmt.Errorf("failed to get file from S3: %w", err)
}
return resp.Body, nil
}
// DeleteFile deletes a file
func (s *s3FileService) DeleteFile(ctx context.Context, filePath string) error {
objectName, err := s.parseS3FilePath(filePath)
if err != nil {
return err
}
_, err = s.client.DeleteObject(ctx, &s3.DeleteObjectInput{
Bucket: aws.String(s.bucketName),
Key: aws.String(objectName),
})
if err != nil {
return fmt.Errorf("failed to delete file: %w", err)View on GitHub (pinned to 988cbb0330)
Solutions
- Verify the object exists (aws s3 ls s3://bucket/objectName) and that the objectName passed to GetFile matches the path returned by SaveFile/SaveBytes
- Check AWS credentials and IAM policy grant s3:GetObject on bucket/objectName
- Unwrap the error with errors.As on smithy APIError to distinguish NoSuchKey vs AccessDenied vs network errors
- Confirm bucketName and region/endpoint configuration are correct for the environment
Example fix
// before
body, err := fileSvc.GetFile(ctx, path)
// after
body, err := fileSvc.GetFile(ctx, path)
if err != nil {
var apiErr smithy.APIError
if errors.As(err, &apiErr) && apiErr.ErrorCode() == "NotFound" {
return fmt.Errorf("file %s not found: %w", path, err)
}
return err
} Defensive patterns
Strategy: try-catch
Validate before calling
// Go: check path format before calling
if !strings.HasPrefix(path, "s3://") { return errors.New("not an s3 path") } Type guard
func isS3Path(p string) bool { return strings.HasPrefix(p, "s3://") } Try / catch
body, err := svc.GetFile(ctx, path)
if err != nil {
var apiErr smithy.APIError
if errors.As(err, &apiErr) && apiErr.ErrorCode() == "NotFound" {
return ErrFileNotFound
}
return err
} Prevention
- Always use paths returned by SaveFile/SaveBytes as input to GetFile
- Map S3 error codes (NotFound, AccessDenied) to domain errors via errors.As
- Log bucket/key on failure to speed up debugging
- Keep bucket policy and IAM in sync with the pathPrefix scheme
When it happens
Trigger: Calling GetFile with an objectName/key that does not exist in the bucket (NoSuchKey), expired or misconfigured credentials, missing s3:GetObject permission on the bucket/key, or network/DNS failures reaching the S3 endpoint.
Common situations: File was deleted or never uploaded under the constructed path (pathPrefix/tenantID/... changed between versions); wrong bucketName in config; IAM policy lacks GetObject; SDK v2 endpoint misconfiguration; VPC without outbound access to S3.
Related errors
- failed to delete file: %w
- failed to upload bytes to S3: %w
- failed to upload file to OBS: %w
- failed to get file from OBS: %w
- failed to copy file in OBS: %w
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/bee125325c8c236e.
Report an issue: GitHub.