{"record":{"id":"f46260ef2d3572d0","repo":"gofr-dev/gofr","slug":"out-of-range-f46260","errorCode":null,"errorMessage":"out of range","messagePattern":"out of range","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gofr/datasource/interface.go","lineNumber":60,"sourceCode":"\n\t// OpenFile opens a file using the given flags and the given mode.\n\tOpenFile(name string, flag int, perm os.FileMode) (File, error)\n\n\t// Remove removes a file identified by name, returning an error, if any\n\t// happens.\n\tRemove(name string) error\n\n\t// RemoveAll removes a directory path and any children it contains. It\n\t// does not fail if the path does not exist (return nil).\n\tRemoveAll(path string) error\n\n\t// Rename renames a file.\n\tRename(oldname, newname string) error\n}\n\nvar (\n\tErrFileClosed        = errors.New(\"File is closed\")\n\tErrOutOfRange        = errors.New(\"out of range\")\n\tErrTooLarge          = errors.New(\"too large\")\n\tErrFileNotFound      = os.ErrNotExist\n\tErrFileExists        = os.ErrExist\n\tErrDestinationExists = os.ErrExist\n)\n\ntype FileSystemProvider interface {\n\tFileSystem\n\n\t// UseLogger sets the logger for the FileSystem client.\n\tUseLogger(logger any)\n\n\t// UseMetrics sets the metrics for the FileSystem client.\n\tUseMetrics(metrics any)\n\n\t// Connect establishes a connection to FileSystem and registers metrics using the provided configuration when the client was Created.\n\tConnect()\n}","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/interface.go#L42-L78","documentation":"ErrOutOfRange is a public sentinel error from the datasource interface, analogous to io.EOF/Bounds errors, returned when a ReadAt or Seek operation requests a position outside the file's bounds. ReadAt returns it when the requested offset exceeds file length; ValidateSeekOffset-based helpers return it for invalid whence or offsets beyond length.","triggerScenarios":"ReadAt(buf, off) with off >= file size; Seek with an invalid whence or a resulting offset beyond the file length (whence-based beyond length cases).","commonSituations":"Reading paged binary data where pagination ran past the end; offsets computed from stale file sizes after the file shrank; misused whence constants in Seek calls.","solutions":["Compare the requested offset against the file size (Stat/Size) before ReadAt/Seek","Treat ErrOutOfRange as end-of-data in read loops (errors.Is check)","Fix whence usage — use io.SeekStart/Current/End constants"],"exampleFix":"// before\nbuf := make([]byte, 10)\nf.ReadAt(buf, int64(size)) // out of range\n// after\nif off >= size {\n    return io.EOF // end of data\n}\nf.ReadAt(buf, off)","handlingStrategy":"type-guard","validationCode":"if off < 0 || off >= fileSize {\n    return io.EOF\n}\nf.ReadAt(buf, off)","typeGuard":"func isOutOfRange(err error) bool {\n    return errors.Is(err, datasource.ErrOutOfRange)\n}","tryCatchPattern":"_, err := f.ReadAt(buf, off)\nif errors.Is(err, datasource.ErrOutOfRange) {\n    return io.EOF // treat as end of data\n}","preventionTips":["Stat the file size before ReadAt/Seek","Use io.Seek* whence constants only","Handle shortened files by re-checking size after modifications"],"tags":["file-io","bounds","seek","gofr"],"backgroundTag":"offset-out-of-range","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}