{"record":{"id":"6909484b0056d0d6","repo":"gofr-dev/gofr","slug":"response-retrieved-is-nil","errorCode":null,"errorMessage":"response retrieved is nil ","messagePattern":"response retrieved is nil ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/file/s3/file.go","lineNumber":40,"sourceCode":"//nolint:revive // s3.S3File is repetitive. A better name could have been chosen, but it's too late as it's already exported.\ntype S3File struct {\n\tconn         s3Client\n\tname         string\n\toffset       int64\n\tlogger       Logger\n\tmetrics      Metrics\n\tsize         int64\n\tcontentType  string\n\tbody         io.ReadCloser\n\tlastModified time.Time\n}\n\nfunc (*S3File) Sys() any {\n\treturn nil\n}\n\nvar (\n\tErrNilResponse = errors.New(\"response retrieved is nil \")\n\t// ErrRangeNotHonored is returned when a byte-range read was requested but the\n\t// backend answered with the whole object (no Content-Range header). Filling the\n\t// caller's buffer from byte 0 in that case would silently serve the wrong bytes,\n\t// so the read is refused instead.\n\tErrRangeNotHonored = errors.New(\"s3 backend did not honor the requested byte range\")\n)\n\n// Close closes the response body returned in Open/Create methods if the response body is not nil.\nfunc (f *S3File) Close() error {\n\tbucketName := getBucketName(f.name)\n\n\tdefer f.sendOperationStats(&FileLog{\n\t\tOperation: \"CLOSE\",\n\t\tLocation:  getLocation(bucketName)}, time.Now())\n\n\tif f.body != nil {\n\t\treturn f.body.Close()\n\t}","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/file/s3/file.go#L22-L58","documentation":"ErrNilResponse is the sentinel error of the GoFr S3 file datasource reported when a GetObject call succeeds at the HTTP level but the returned response body is nil, so there is no data stream to read from. It is wrapped by Read as '%w: S3 file is empty', meaning the S3 object could not be materialized into a readable body. This is a defensive check against SDK/proxy anomalies rather than a normal user error.","triggerScenarios":"Calling (*S3File).Read when the underlying s3.GetObjectOutput has a nil Body — e.g. an S3-compatible backend (MinIO, mock, or misbehaving proxy) returns a 200 with no body stream, or a test/mock client returns an output struct without Body.","commonSituations":"Pointing the datasource at non-AWS S3-compatible stores that don't fully honor the GetObject contract; using fake/mocked AWS clients in tests that forget Body; SDK version mismatches where output struct fields change.","solutions":["Check that the target S3-compatible backend actually returns a body stream for GetObject (curl/S3 console or aws s3 cp the object to confirm it is retrievable).","Upgrade github.com/aws/aws-sdk-go-v2 and the gofr module to latest versions to rule out SDK field-contract changes.","If using a mock S3 client, populate GetObjectOutput.Body (e.g. io.NopCloser(bytes.NewReader(data))) instead of returning an empty struct.","Handle the error with errors.Is(err, s3.ErrNilResponse) and treat it as a failed/retryable read rather than nil-data."],"exampleFix":"// before: mock returns empty output\nres := &s3.GetObjectOutput{}\n// after\nres := &s3.GetObjectOutput{Body: io.NopCloser(bytes.NewReader(objBytes))}","handlingStrategy":"try-catch","validationCode":"// no pre-call validation possible; ensure backend/mocks supply a Body\n// when stubbing:\n// out := &s3.GetObjectOutput{Body: io.NopCloser(bytes.NewReader(data))}","typeGuard":null,"tryCatchPattern":"n, err := f.Read(buf)\nif err != nil {\n    if errors.Is(err, s3datasource.ErrNilResponse) {\n        // backend returned no body: fail fast or retry once\n    }\n    return err\n}","preventionTips":["Use conformant S3 backends (real S3, recent MinIO).","Always populate Body in mocked GetObjectOutput.","Keep aws-sdk-go-v2 and gofr versions current.","Wrap reads with errors.Is checks for sentinel errors."],"tags":["s3","aws-sdk","nil-response","gofr"],"backgroundTag":"nil-response-body","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}