affaan-m/ECC · error · Error
Invalid limit
Error message
Invalid limit: ${value} What it means
normalizeLimit turns an optional limit value into a positive integer, falling back to a default when undefined/null. Any other input that does not parse (via parseInt) into a finite positive integer — 0, negative numbers, NaN, floats with fraction, non-numeric strings — throws. It backs limit, activeLimit, recentSkillRunLimit, pendingLimit, and workItemLimit query options.
Solutions
- Pass a positive integer (or omit the value to use the fallback)
- Coerce and validate at the boundary: n = Number.parseInt(raw, 10); if (!Number.isFinite(n) || n <= 0) use default
- Fix upstream parsing so numeric query params are converted before reaching the query layer
- Remove sentinel values like 0 or -1 meant to mean 'unlimited' — omit the option instead
Example fix
// before
queryActive({ limit: 0 });
// after
const limit = Number(rawLimit);
queryActive({ limit: Number.isFinite(limit) && limit > 0 ? limit : undefined }); Defensive patterns
Strategy: validation
Validate before calling
function toLimit(raw, fallback) {
if (raw === undefined || raw === null) return fallback;
const n = Number.parseInt(raw, 10);
return Number.isFinite(n) && n > 0 ? n : fallback;
}
const limit = toLimit(rawLimit, 50); Type guard
function isValidLimit(v) {
const n = Number(v);
return Number.isInteger(n) && n > 0;
} Try / catch
try {
return queryActive({ limit });
} catch (err) {
if (err.message.startsWith('Invalid limit')) {
console.warn(`Bad limit '${limit}' — using default`);
return queryActive({});
} throw err;
} Prevention
- Sanitize user/HTTP/CLI limit input at the boundary with parseInt and a range check
- Use undefined, not 0 or -1, to mean 'use the default'
- Validate numeric config keys at startup
- Never forward raw string query params into query options
When it happens
Trigger: Calling a query function with limit: 0, limit: -5, limit: 'ten', limit: 2.5, or limit: NaN; passing a limit string like '10abc' which parseInt yields 10 for but 'abc' yields NaN for and throws.
Common situations: User-supplied pagination values passed through from CLI/HTTP without validation; off-by-one code computing limit as count-1 when count is 0; environment/config variables holding placeholder text; JSON configs where the limit was accidentally an object or empty string.
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
- page_size must be greater than 0
- -32602
- a claim token is required
- a confirmed nonempty coordinate is required
- a generated candidate cannot claim original-source identity
AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16).
Data as JSON: /api/errors/e89de0f785b3259f.
Report an issue: GitHub.
Appendix: source
Thrown at scripts/lib/state-store/queries.js:18
'use strict';
const { assertValidEntity } = require('./schema');
const ACTIVE_SESSION_STATES = ['active', 'running', 'idle'];
const SUCCESS_OUTCOMES = new Set(['success', 'succeeded', 'passed']);
const FAILURE_OUTCOMES = new Set(['failure', 'failed', 'error']);
const CLOSED_WORK_ITEM_STATUSES = new Set(['done', 'closed', 'resolved', 'merged', 'cancelled']);
const ATTENTION_WORK_ITEM_STATUSES = new Set(['blocked', 'needs-review', 'failed', 'stalled']);
function normalizeLimit(value, fallback) {
if (value === undefined || value === null) {
return fallback;
}
const parsed = Number.parseInt(value, 10);
if (!Number.isFinite(parsed) || parsed <= 0) {
throw new Error(`Invalid limit: ${value}`);
}
return parsed;
}
function parseJsonColumn(value, fallback) {
if (value === null || value === undefined || value === '') {
return fallback;
}
return JSON.parse(value);
}
function stringifyJson(value, label) {
try {
return JSON.stringify(value);
} catch (error) {
throw new Error(`Failed to serialize ${label}: ${error.message}`);View on GitHub (pinned to 8321021c54)