{"record":{"id":"68d2b5ed974b4f8a","repo":"JuliusBrussee/caveman","slug":"objectstore-page-size-must-be-positive","errorCode":null,"errorMessage":"objectstore: page size must be positive","messagePattern":"objectstore: page size must be positive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/objectstore/objectstore.go","lineNumber":75,"sourceCode":"type ObjectPage struct {\n\tKeys      []string\n\tNextToken string\n\tTruncated bool\n}\n\n// PagedLister is implemented by production backends and bounded test stores.\n// A retention sweep must use this interface rather than materializing an\n// unbounded Store.List result.\ntype PagedLister interface {\n\tListPage(ctx context.Context, prefix, startAfter string, maxKeys int) (ObjectPage, error)\n}\n\n// ListPage dispatches to a cursor-capable backend. It intentionally does not\n// fall back to Store.List: callers use it specifically to preserve a memory\n// bound when a tenant prefix is large.\nfunc ListPage(ctx context.Context, store Store, prefix, startAfter string, maxKeys int) (ObjectPage, error) {\n\tif maxKeys <= 0 {\n\t\treturn ObjectPage{}, fmt.Errorf(\"objectstore: page size must be positive\")\n\t}\n\tlister, ok := store.(PagedLister)\n\tif !ok {\n\t\treturn ObjectPage{}, ErrPagingUnsupported\n\t}\n\treturn lister.ListPage(ctx, prefix, startAfter, maxKeys)\n}\n\n// VersionPurger is implemented by version-aware backends. Explicit privacy\n// deletion uses it to remove current objects, noncurrent versions, and delete\n// markers immediately instead of waiting for lifecycle expiration.\ntype VersionPurger interface {\n\tDeleteAllVersions(ctx context.Context, key string) error\n\tDeletePrefixAllVersions(ctx context.Context, prefix string) error\n}\n\n// PurgeObject removes every version when supported, falling back to ordinary\n// deletion only for non-versioned test/self-hosted backends.","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/objectstore/objectstore.go#L57-L93","documentation":"ListPage rejects a non-positive maxKeys with 'objectstore: page size must be positive' before touching the backend. The library throws it because paging exists to bound memory, and a zero/negative page size is meaningless; it fails fast instead of producing backend-specific behavior.","triggerScenarios":"Calling objectstore.ListPage(ctx, store, prefix, startAfter, 0) or with a negative maxKeys — usually a page-size variable defaulted from an unset config or int zero-value.","commonSituations":"Page size loaded from config/env where the key is missing and no default applied; computing maxKeys from a division that rounds to 0; copying example code that leaves maxKeys unset.","solutions":["Pass a positive maxKeys (e.g. 1000); apply a default when the configured value is <=0.","Validate page-size config at startup and refuse to run with a non-positive value.","Clamp computed sizes: if maxKeys <= 0 { maxKeys = defaultPageSize }."],"exampleFix":"// before\npage, err := objectstore.ListPage(ctx, store, prefix, startAfter, cfg.PageSize) // cfg.PageSize == 0\n// after\npageSize := cfg.PageSize\nif pageSize <= 0 {\n    pageSize = 1000\n}\npage, err := objectstore.ListPage(ctx, store, prefix, startAfter, pageSize)","handlingStrategy":"validation","validationCode":"func validPageSize(n int) bool { return n > 0 }\nif !validPageSize(maxKeys) { maxKeys = 1000 }","typeGuard":null,"tryCatchPattern":"page, err := objectstore.ListPage(ctx, store, prefix, startAfter, maxKeys)\nif err != nil && strings.Contains(err.Error(), \"page size must be positive\") {\n    return fmt.Errorf(\"configure a positive page size (got %d)\", maxKeys)\n}","preventionTips":["Default page size at config load (e.g. 1000) when unset.","Validate page-size env/config values at startup.","Watch for computed sizes that can round down to 0."],"tags":["paging","invalid-argument","objectstore"],"backgroundTag":"invalid-argument-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}