{"record":{"id":"c3749ad7baf69f13","repo":"Tencent/WeKnora","slug":"failed-to-get-file-from-obs-w","errorCode":null,"errorMessage":"failed to get file from OBS: %w","messagePattern":"failed to get file from OBS: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/file/obs.go","lineNumber":202,"sourceCode":"\tprefix := s.getPrifix()\n\tif s.proxyDomain != \"\" {\n\t\treturn fmt.Sprintf(\"%s%s\", prefix, objectKey), nil\n\t}\n\treturn fmt.Sprintf(\"%s%s/%s\", prefix, s.bucketName, objectKey), nil\n}\n\nfunc (s *obsFileService) GetFile(ctx context.Context, filePath string) (io.ReadCloser, error) {\n\tobjectKey, err := s.parseObsFilePath(filePath)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\toutput, err := s.client.GetObject(ctx, &s3.GetObjectInput{\n\t\tBucket: aws.String(s.bucketName),\n\t\tKey:    aws.String(objectKey),\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get file from OBS: %w\", err)\n\t}\n\n\treturn output.Body, nil\n}\n\nfunc (s *obsFileService) DeleteFile(ctx context.Context, filePath string) error {\n\tobjectKey, err := s.parseObsFilePath(filePath)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t_, err = s.client.DeleteObject(ctx, &s3.DeleteObjectInput{\n\t\tBucket: aws.String(s.bucketName),\n\t\tKey:    aws.String(objectKey),\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to delete file from OBS: %w\", err)\n\t}","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/file/obs.go#L184-L220","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nif err != nil { return nil, fmt.Errorf(\"failed to get file from OBS: %w\", err) }\n// after\nvar nf *types.NotFound\nif err != nil {\n    if errors.As(err, &nf) || strings.Contains(err.Error(), \"NoSuchKey\") {\n        return nil, ErrFileNotFound\n    }\n    return nil, fmt.Errorf(\"failed to get file from OBS: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"r, err := svc.GetFile(ctx, p)\nif err != nil {\n    if strings.Contains(err.Error(), \"NoSuchKey\") || strings.Contains(err.Error(), \"NotFound\") {\n        http.NotFound(w, r)\n        return\n    }\n    http.Error(w, \"storage error\", http.StatusInternalServerError)\n}","preventionTips":["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"],"tags":["obs","s3","download","network"],"backgroundTag":"object-storage-download-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}