laurent22/joplin · error · Error
Note count must be specified
Error message
Note count must be specified
What it means
Thrown by the `itemCount` helper in command-testing.ts when `Number(args.arg0)` is falsy or NaN — i.e. the user did not supply a valid numeric count for the `createRandomNotes`, `updateRandomNotes`, or `deleteRandomNotes` testing subcommands. The helper is the single chokepoint that parses `[arg0]` into a loop bound, so any non-numeric or zero value is rejected before the random-note loop runs.
Source
Thrown at packages/app-cli/app/command-testing.ts:16
import BaseCommand from './base-command';
import { reg } from '@joplin/lib/registry';
import Note from '@joplin/lib/models/Note';
import uuid from '@joplin/lib/uuid';
import populateDatabase from '@joplin/lib/services/debug/populateDatabase';
import { readCredentialFile } from '@joplin/lib/utils/credentialFiles';
import JoplinServerApi, { Session } from '@joplin/lib/JoplinServerApi';
function randomElement<T>(array: T[]): T | null {
if (!array.length) return null;
return array[Math.floor(Math.random() * array.length)];
}
function itemCount(args: { arg0: string }) {
const count = Number(args.arg0);
if (!count || isNaN(count)) throw new Error('Note count must be specified');
return count;
}
class Command extends BaseCommand {
public usage() {
return 'testing <command> [arg0]';
}
public description() {
return 'testing';
}
public enabled() {
return false;
}
public options(): [string, string][] {
return [View on GitHub (pinned to 2654b33620)
Solutions
- Supply a positive integer: `:testing createRandomNotes 100`.
- When scripting, coerce and validate the count before invoking: ensure it is a finite positive number.
- If the command is not enabled in your build, use `populate` with `--note-count` instead, which takes counts as options.
Example fix
// before
const count = Number(args.arg0);
if (!count || isNaN(count)) throw new Error('Note count must be specified');
// after - distinguish 'missing' from 'invalid' and accept only positive integers
const count = Number(args.arg0);
if (args.arg0 === undefined) throw new Error('Note count must be specified');
if (!Number.isInteger(count) || count <= 0) throw new Error(`Note count must be a positive integer (got "${args.arg0}")`); Defensive patterns
Strategy: validation
Validate before calling
const count = Number(args.arg0);
if (args.arg0 === undefined || !Number.isInteger(count) || count <= 0) {
throw new Error(`Note count must be a positive integer (got "${args.arg0}")`);
} Type guard
const isPositiveInt = (v: unknown): v is number => typeof v === 'number' && Number.isInteger(v) && v > 0;
Try / catch
try {
await app().executeCommand(['testing', 'createRandomNotes', String(count)]);
} catch (e) {
if (/Note count must be specified/.test(e.message)) { /* reprompt for a valid count */ }
else throw e;
} Prevention
- Coerce and validate the count to a positive integer before invoking.
- Remember the testing command is disabled in release builds.
- Prefer the `populate` subcommand with `--note-count` for scripted data generation.
When it happens
Trigger: Running `:testing createRandomNotes` (no arg), `:testing updateRandomNotes abc`, or any value where `Number(arg)` is 0/NaN. Note the command itself is disabled by default (`enabled()` returns false), so this only fires in development builds where the testing command is reachable.
Common situations: Forgot the count argument; passed a non-numeric string; scripting with an unset count variable; calling the disabled command in a release build (it would not be reachable).
Related errors
- [notebook] is required
- [user] is required
- Unknown subcommand: ${args.command}
- Invalid command: "%s"
- More than one item match "%s". Please narrow down your query
AI-assisted analysis of laurent22/joplin@2654b33620 (2026-08-12).
Data as JSON: /api/errors/14e2a5bf3dea5627.
Report an issue: GitHub.