Stirling-Tools/Stirling-PDF · warning · Error
Expected number
Error message
Expected number
What it means
Thrown by readRequiredNumber when tryReadNumber returns null — i.e. the next characters are not leading digits. It is called after a '-' in a range (number '-' number), so this specifically means a range's end value is missing or non-numeric. Like sibling parser errors, it is caught by the CSV fallback unless strict mode is on.
Source
Thrown at frontend/editor/src/core/utils/bulkselection/parseSelection.ts:336
return null;
}
c = sign === "-" ? -cVal : cVal;
}
return { k, c };
}
private tryReadNumber(): number | null {
this.skipWs();
const m = this.src.slice(this.idx).match(/^(\d+)/);
if (!m) return null;
this.consume(m[1].length);
const num = parseInt(m[1], 10);
return Number.isFinite(num) ? num : null;
}
private readRequiredNumber(): number {
const n = this.tryReadNumber();
if (n === null) throw new Error("Expected number");
return n;
}
private readWord(): string | null {
this.skipWs();
const m = this.src.slice(this.idx).match(/^([A-Za-z]+)/);
if (!m) return null;
this.consume(m[1].length);
return m[1];
}
private tryConsumeNot(): boolean {
const start = this.idx;
const word = this.readWord();
if (!word) {
this.idx = start;
return false;
}View on GitHub (pinned to 9ef20dcab8)
Solutions
- Complete every range with an end number: 'start-end', e.g. '1-10'.
- Remove a trailing '-' if a single page was intended ('1' not '1-').
- Validate with a regex like /^\d+\s*-\s*\d+$/ per token before submitting in strict contexts.
- Use the diagnostics warning to flag incomplete ranges before strict enforcement.
Example fix
// before
parseSelectionWithDiagnostics('1-', max, { strict: true })
// after
parseSelectionWithDiagnostics('1-10', max, { strict: true }) Defensive patterns
Strategy: validation
Validate before calling
function rangesAreComplete(input: string): boolean {
return input.split(',').every(tok => !/\d\s*-\s*$/.test(tok.trim()));
}
if (!rangesAreComplete(input)) {
showUser('Every range must have an end number (e.g. 1-10).');
} Type guard
function isCompleteRangeToken(tok: string): boolean {
return /^\d+\s*-\s*\d+$/.test(tok.trim()) || /^\d+$/.test(tok.trim());
} Try / catch
try {
const { pages } = parseSelectionWithDiagnostics(input, maxPages, { strict: true });
} catch (e) {
if (e instanceof Error && e.message === 'Expected number') {
showUser('A range is missing its end number.');
} else { throw e; }
} Prevention
- Always provide both ends of a range ('1-10', not '1-').
- Validate each comma-separated token with a regex before strict parsing.
- Use non-strict mode to fall back to CSV and warn.
- Show a live count of matched pages so incomplete ranges are obvious.
When it happens
Trigger: Input like '1-' (range with no end), '1-a' (range end is a letter), or '5-' followed by end-of-string. The parser read the start number, consumed '-', then expected digits but found none.
Common situations: User typed an incomplete range and submitted, or a trailing '-' was left from editing. Strict mode surfaces the error; non-strict falls back to CSV (which ignores the malformed token).
Related errors
- Unexpected trailing input
- Expected )
- Expected primary
- PDFium: failed to load page ${pageIndex}
- No team resolved yet
AI-assisted analysis of Stirling-Tools/Stirling-PDF@9ef20dcab8 (2026-08-13).
Data as JSON: /api/errors/0f4b728bd3a02069.
Report an issue: GitHub.