mastra-ai/mastra · error
page value too large
Error message
page value too large
What it means
The in-memory scorer-definitions list() throws when page * perPage exceeds Number.MAX_SAFE_INTEGER / 2, guarding offset math against unsafe-integer overflow. It is a deterministic input guard, not a size limit on stored data.
Source
Thrown at packages/core/src/storage/domains/scorer-definitions/inmemory.ts:150
authorId,
organizationId,
projectId,
metadata,
status,
} = args || {};
const { field, direction } = this.parseOrderBy(orderBy);
// Normalize perPage for query (false → MAX_SAFE_INTEGER, 0 → 0, undefined → 100)
const perPage = normalizePerPage(perPageInput, 100);
if (page < 0) {
throw new Error('page must be >= 0');
}
// Prevent unreasonably large page values
const maxOffset = Number.MAX_SAFE_INTEGER / 2;
if (page * perPage > maxOffset) {
throw new Error('page value too large');
}
// Get all scorer definitions and apply filters
let scorers = Array.from(this.db.scorerDefinitions.values());
// Filter by status
if (status) {
scorers = scorers.filter(scorer => scorer.status === status);
}
// Filter by authorId if provided
if (authorId !== undefined) {
scorers = scorers.filter(scorer => scorer.authorId === authorId);
}
// Filter by organizationId if provided (multi-tenant scoping)
if (organizationId !== undefined) {
scorers = scorers.filter(scorer => scorer.organizationId === organizationId);View on GitHub (pinned to 75dd419e61)
Solutions
- Fetch everything with list({ page: 0, perPage: false }) instead of a huge page.
- Page normally from 0 upward, stopping when a page returns fewer than perPage items.
- Clamp page to a sane maximum derived from your expected record count.
- Sanitize/validate page numbers coming from external input before calling list().
Example fix
// before
await storage.scorerDefinitions.list({ page: Number.MAX_SAFE_INTEGER });
// after
await storage.scorerDefinitions.list({ page: 0, perPage: false }); Defensive patterns
Strategy: validation
Validate before calling
const MAX_OFFSET = Number.MAX_SAFE_INTEGER / 2;
function guardPage(page: number, perPage: number): void {
if (page * perPage > MAX_OFFSET) throw new RangeError('page value too large for scorer list');
} Type guard
function paginationIsSafe(page: number, perPage: number): boolean {
return Number.isInteger(page) && page >= 0 && page * perPage <= Number.MAX_SAFE_INTEGER / 2;
} Try / catch
try {
return await storage.scorerDefinitions.list({ page, perPage });
} catch (e) {
if (e instanceof Error && e.message === 'page value too large') {
return storage.scorerDefinitions.list({ page: 0, perPage: false });
}
throw e;
} Prevention
- Use { page: 0, perPage: false } for 'fetch all'; never a huge page.
- Cap user-supplied page numbers before calling list().
- With perPage: false, perPage becomes MAX_SAFE_INTEGER — only use page 0 there.
- Loop pages sequentially from 0 rather than computing a distant page.
When it happens
Trigger: Calling list({ page: 1e15 }) or list({ page: Number.MAX_SAFE_INTEGER }); combining a moderately large page with perPage: false, where perPage normalizes to MAX_SAFE_INTEGER and page * perPage instantly exceeds the cap.
Common situations: MAX_SAFE_INTEGER used as a 'get everything' page sentinel; unbounded user-supplied page numbers; composing perPage: false with pagination loops instead of a single call.
Related errors
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/83e276d56d71f7b8.
Report an issue: GitHub.