{"record":{"id":"14e2a5bf3dea5627","repo":"laurent22/joplin","slug":"note-count-must-be-specified","errorCode":null,"errorMessage":"Note count must be specified","messagePattern":"Note count must be specified","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/app-cli/app/command-testing.ts","lineNumber":16,"sourceCode":"import BaseCommand from './base-command';\nimport { reg } from '@joplin/lib/registry';\nimport Note from '@joplin/lib/models/Note';\nimport uuid from '@joplin/lib/uuid';\nimport populateDatabase from '@joplin/lib/services/debug/populateDatabase';\nimport { readCredentialFile } from '@joplin/lib/utils/credentialFiles';\nimport JoplinServerApi, { Session } from '@joplin/lib/JoplinServerApi';\n\nfunction randomElement<T>(array: T[]): T | null {\n\tif (!array.length) return null;\n\treturn array[Math.floor(Math.random() * array.length)];\n}\n\nfunction itemCount(args: { arg0: string }) {\n\tconst count = Number(args.arg0);\n\tif (!count || isNaN(count)) throw new Error('Note count must be specified');\n\treturn count;\n}\n\nclass Command extends BaseCommand {\n\tpublic usage() {\n\t\treturn 'testing <command> [arg0]';\n\t}\n\n\tpublic description() {\n\t\treturn 'testing';\n\t}\n\n\tpublic enabled() {\n\t\treturn false;\n\t}\n\n\tpublic options(): [string, string][] {\n\t\treturn [","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/laurent22/joplin/blob/2654b33620775080d1d59c552259d41e33dad3d2/packages/app-cli/app/command-testing.ts#L1-L34","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\nconst count = Number(args.arg0);\nif (!count || isNaN(count)) throw new Error('Note count must be specified');\n\n// after - distinguish 'missing' from 'invalid' and accept only positive integers\nconst count = Number(args.arg0);\nif (args.arg0 === undefined) throw new Error('Note count must be specified');\nif (!Number.isInteger(count) || count <= 0) throw new Error(`Note count must be a positive integer (got \"${args.arg0}\")`);","handlingStrategy":"validation","validationCode":"const count = Number(args.arg0);\nif (args.arg0 === undefined || !Number.isInteger(count) || count <= 0) {\n\tthrow new Error(`Note count must be a positive integer (got \"${args.arg0}\")`);\n}","typeGuard":"const isPositiveInt = (v: unknown): v is number => typeof v === 'number' && Number.isInteger(v) && v > 0;","tryCatchPattern":"try {\n\tawait app().executeCommand(['testing', 'createRandomNotes', String(count)]);\n} catch (e) {\n\tif (/Note count must be specified/.test(e.message)) { /* reprompt for a valid count */ }\n\telse throw e;\n}","preventionTips":["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."],"tags":["testing","argument-validation","numeric","cli","dev-only"],"backgroundTag":null,"analyzedSha":"2654b33620775080d1d59c552259d41e33dad3d2","analyzedAt":"2026-08-12T14:26:46.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}