JuliusBrussee/caveman · error

objectstore: page size must be positive

Error message

objectstore: page size must be positive

What it means

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.

Solutions

  1. Pass a positive maxKeys (e.g. 1000); apply a default when the configured value is <=0.
  2. Validate page-size config at startup and refuse to run with a non-positive value.
  3. Clamp computed sizes: if maxKeys <= 0 { maxKeys = defaultPageSize }.

Example fix

// before
page, err := objectstore.ListPage(ctx, store, prefix, startAfter, cfg.PageSize) // cfg.PageSize == 0
// after
pageSize := cfg.PageSize
if pageSize <= 0 {
    pageSize = 1000
}
page, err := objectstore.ListPage(ctx, store, prefix, startAfter, pageSize)
Defensive patterns

Strategy: validation

Validate before calling

func validPageSize(n int) bool { return n > 0 }
if !validPageSize(maxKeys) { maxKeys = 1000 }

Try / catch

page, err := objectstore.ListPage(ctx, store, prefix, startAfter, maxKeys)
if err != nil && strings.Contains(err.Error(), "page size must be positive") {
    return fmt.Errorf("configure a positive page size (got %d)", maxKeys)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/68d2b5ed974b4f8a. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/objectstore/objectstore.go:75

type ObjectPage struct {
	Keys      []string
	NextToken string
	Truncated bool
}

// PagedLister is implemented by production backends and bounded test stores.
// A retention sweep must use this interface rather than materializing an
// unbounded Store.List result.
type PagedLister interface {
	ListPage(ctx context.Context, prefix, startAfter string, maxKeys int) (ObjectPage, error)
}

// ListPage dispatches to a cursor-capable backend. It intentionally does not
// fall back to Store.List: callers use it specifically to preserve a memory
// bound when a tenant prefix is large.
func ListPage(ctx context.Context, store Store, prefix, startAfter string, maxKeys int) (ObjectPage, error) {
	if maxKeys <= 0 {
		return ObjectPage{}, fmt.Errorf("objectstore: page size must be positive")
	}
	lister, ok := store.(PagedLister)
	if !ok {
		return ObjectPage{}, ErrPagingUnsupported
	}
	return lister.ListPage(ctx, prefix, startAfter, maxKeys)
}

// VersionPurger is implemented by version-aware backends. Explicit privacy
// deletion uses it to remove current objects, noncurrent versions, and delete
// markers immediately instead of waiting for lifecycle expiration.
type VersionPurger interface {
	DeleteAllVersions(ctx context.Context, key string) error
	DeletePrefixAllVersions(ctx context.Context, prefix string) error
}

// PurgeObject removes every version when supported, falling back to ordinary
// deletion only for non-versioned test/self-hosted backends.

View on GitHub (pinned to 3ee70a1026)