{"record":{"id":"4e1cd1ca5b477221","repo":"gofr-dev/gofr","slug":"out-of-range-4e1cd1","errorCode":null,"errorMessage":"out of range","messagePattern":"out of range","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/file/s3/file_parse.go","lineNumber":22,"sourceCode":"\t\"bufio\"\n\t\"bytes\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"io\"\n\t\"os\"\n\t\"path\"\n\t\"path/filepath\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/aws/aws-sdk-go-v2/aws\"\n\tfile \"gofr.dev/pkg/gofr/datasource/file\"\n)\n\nvar (\n\t// errNotPointer is returned when Read method is called with a non-pointer argument.\n\terrStringNotPointer = errors.New(\"input should be a pointer to a string\")\n\tErrOutOfRange       = errors.New(\"out of range\")\n)\n\nconst (\n\tstatusErr     = \"ERROR\"\n\tstatusSuccess = \"SUCCESS\"\n)\n\n// textReader implements RowReader for reading text files.\ntype textReader struct {\n\tscanner *bufio.Scanner\n\tlogger  Logger\n}\n\n// jsonReader implements RowReader for reading JSON files.\ntype jsonReader struct {\n\tdecoder *json.Decoder\n\ttoken   json.Token\n}","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/file/s3/file_parse.go#L4-L40","documentation":"ErrOutOfRange is the public sentinel for position-related failures in the S3 datasource. It is wrapped by ReadAt for negative offsets and returned by seek-offset validation when the requested position is invalid (bad whence, negative resulting offset, or offset beyond the known object length). Check with errors.Is(err, s3.ErrOutOfRange).","triggerScenarios":"1) ReadAt with a negative offset; 2) Seek to a resulting offset < 0; 3) Seek with an invalid whence; 4) Seek/position beyond the object length where validation rejects it. Test references show seek validation paths (validateSeekOffset) return it too.","commonSituations":"Seeking past end of file expecting os.File semantics (this implementation rejects it); arithmetic underflow producing negative offsets; using a whence constant outside 0/1/2.","solutions":["Clamp offsets to [0, size] before Seek/ReadAt; get the size via Stat().","Use only os.SEEK_SET/SEEK_CUR/SEEK_END constants.","Distinguish EOF semantics: for ReadAt, offsets >= size return io.EOF, negatives return this error — validate inputs accordingly.","Match with errors.Is(err, s3.ErrOutOfRange) and surface a 4xx-style caller error rather than retrying."],"exampleFix":"// before\n_, err := f.Seek(int64(size+10), io.SeekStart) // out of range\n// after\nif newOff < 0 || newOff > size { return ErrOutOfRange }\n_, err := f.Seek(newOff, io.SeekStart)","handlingStrategy":"validation","validationCode":"fi, _ := f.Stat()\nsize := fi.Size()\nfunc safeSeek(f *s3datasource.S3File, off int64) error {\n    if off < 0 || off > size {\n        return fmt.Errorf(\"offset %d out of [0,%d]\", off, size)\n    }\n    _, err := f.Seek(off, io.SeekStart)\n    return err\n}","typeGuard":"func inRange(off, size int64) bool { return off >= 0 && off <= size }","tryCatchPattern":"_, err := f.Seek(off, io.SeekStart)\nif errors.Is(err, s3datasource.ErrOutOfRange) {\n    // clamp and retry: off = min(max(off,0), size)\n}","preventionTips":["Stat the object and clamp offsets to [0, size].","Use only the io.SeekStart/Current/End constants.","Handle offsets >= size as EOF (io.EOF), not errors.","Distinguish ErrOutOfRange (caller bug) from I/O errors when logging."],"tags":["out-of-range","seek","validation","s3","gofr"],"backgroundTag":"invalid-offset","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}