diegosouzapw/OmniRoute · error
head requires a positive 'n'
Error message
head requires a positive 'n'
What it means
ccrQuery head validation: the query block's head mode received an 'n' that is not a finite number >= 1 (undefined, 0, negative, NaN, fractional-below-1). clampCount returns null and the helper returns this validation error instead of slicing.
Solutions
- Set n to a positive integer (>= 1)
- Omit n if the default count is acceptable
- Remember n is clamped to MAX_RANGE_LINES (10000)
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at open-sse/services/compression/engines/ccr/ccrQuery.ts:38 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25).
Data as JSON: /api/errors/061e5c58594ecc90.
Report an issue: GitHub.
Appendix: source
Thrown at open-sse/services/compression/engines/ccr/ccrQuery.ts:38
}
export type CcrQueryResult = { content: string } | { error: string };
export const MAX_RANGE_LINES = 10_000;
export const MAX_GREP_MATCHES = 1_000;
export const MAX_PATTERN_LEN = 512;
const err = (m: string): CcrQueryResult => ({ error: m });
const ok = (c: string): CcrQueryResult => ({ content: c });
function clampCount(n: number | undefined): number | null {
if (typeof n !== "number" || !Number.isFinite(n) || n < 1) return null;
return Math.min(Math.floor(n), MAX_RANGE_LINES);
}
function sliceHead(lines: string[], n: number | undefined): CcrQueryResult {
const c = clampCount(n);
if (c === null) return err("head requires a positive 'n'");
return ok(lines.slice(0, c).join("\n"));
}
function sliceTail(lines: string[], n: number | undefined): CcrQueryResult {
const c = clampCount(n);
if (c === null) return err("tail requires a positive 'n'");
return ok(lines.slice(Math.max(0, lines.length - c)).join("\n"));
}
function sliceLines(lines: string[], start?: number, end?: number): CcrQueryResult {
if (typeof start !== "number" || typeof end !== "number" || start < 1 || end < 1) {
return err("lines requires positive 'start' and 'end' (1-indexed)");
}
if (start > end) return err("lines: 'start' must be <= 'end'");
return ok(lines.slice(start - 1, Math.min(end, lines.length)).join("\n"));
}
function grepLines(lines: string[], pattern?: string, unique?: boolean): CcrQueryResult {View on GitHub (pinned to a179ffed5b)