{"record":{"id":"ad68b4c2f64fcd60","repo":"gofr-dev/gofr","slug":"too-large","errorCode":null,"errorMessage":"too large","messagePattern":"too large","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gofr/datasource/interface.go","lineNumber":61,"sourceCode":"\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}\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/interface.go#L43-L79","documentation":"ErrTooLarge is a public sentinel error in the gofr datasource interface package, mirroring os.ErrInvalid/io errors: it indicates a requested read/write or offset value exceeds the maximum supported size. It exists so provider implementations return a consistent error across datasources.","triggerScenarios":"Operations requesting sizes or offsets exceeding implementation limits (e.g. reads larger than the allowed max, or offsets overflowing int64 bounds) in datasource file implementations.","commonSituations":"Allocating huge buffers based on untrusted length headers; files larger than the backend supports; casting sizes that overflow on 32-bit platforms.","solutions":["Cap read/write sizes to a sane maximum before calling","Stream data in chunks instead of one huge read","Validate size fields from untrusted sources"],"exampleFix":"// before\nbuf := make([]byte, declaredLen) // too large\n// after\nconst maxChunk = 1 << 20\nbuf := make([]byte, min(declaredLen, maxChunk))","handlingStrategy":"validation","validationCode":"const maxRead = 1 << 24\nif int64(len(buf)) > maxRead {\n    return fmt.Errorf(\"read size %d exceeds max %d\", len(buf), maxRead)\n}","typeGuard":"func isTooLarge(err error) bool {\n    return errors.Is(err, datasource.ErrTooLarge)\n}","tryCatchPattern":"_, err := f.Read(buf)\nif errors.Is(err, datasource.ErrTooLarge) {\n    // chunk the read into smaller pieces\n}","preventionTips":["Chunk large I/O instead of single huge reads","Bound sizes derived from untrusted input","Prefer streaming over whole-file buffering"],"tags":["file-io","limits","gofr"],"backgroundTag":"payload-too-large","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}