{"record":{"id":"e81db1ddd5ed787f","repo":"can1357/oh-my-pi","slug":"error-message-e81db1","errorCode":null,"errorMessage":"Error: ${message}","messagePattern":"Error: (.+?)","errorType":"exception","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"packages/mnemopi/src/cli.ts","lineNumber":46,"sourceCode":"\t\treadonly exitCode = 2,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"CliError\";\n\t}\n}\n\ntype CommandHandler = (args: readonly string[], context?: CliContext) => number | Promise<number>;\n\nfunction out(context: CliContext | undefined, text = \"\"): void {\n\t(context?.stdout ?? Bun.stdout).write(`${text}\\n`);\n}\n\nfunction err(context: CliContext | undefined, text = \"\"): void {\n\t(context?.stderr ?? Bun.stderr).write(`${text}\\n`);\n}\n\nfunction fail(message: string, exitCode = 2): never {\n\tthrow new CliError(`Error: ${message}`, exitCode);\n}\n\nfunction usage(message: string): never {\n\tthrow new CliError(message, 2);\n}\n\nfunction parseFloatArg(value: string, name: string): number {\n\tconst parsed = Number(value);\n\tif (!Number.isFinite(parsed)) fail(`${name} must be a number: ${value}`);\n\treturn parsed;\n}\n\nfunction parseIntArg(value: string, name: string): number {\n\tif (!/^[+-]?\\d+$/.test(value)) fail(`${name} must be an integer: ${value}`);\n\tconst parsed = Number(value);\n\tif (!Number.isSafeInteger(parsed)) fail(`${name} must be an integer: ${value}`);\n\treturn parsed;\n}","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/mnemopi/src/cli.ts#L28-L64","documentation":"fail() is the mnemopi CLI's error helper: it wraps a message in a CliError with prefix \"Error: \" and default exit code 2. It is used by argument parsers (parseIntArg/parseFloatArg) and commands (import, update, delete, scratchpad) to abort on invalid user input.","triggerScenarios":"Invoking mnemopi CLI subcommands with invalid arguments — non-numeric values where parseIntArg/parseFloatArg expect numbers, unknown ids for update/delete, or missing/invalid scratchpad arguments.","commonSituations":"Typo'd or deleted memory id passed to `mnemopi update`/`delete`; passing a string like 'abc' or '1.5' to an integer flag; forgetting a required argument in scripts.","solutions":["Read the message after 'Error: ' — it names the invalid argument or missing id","For id errors, list memories first (e.g. via the appropriate list/search command) to get a valid id","For numeric errors, pass a valid number matching the expected type (integer vs float)","Run the command with usage/help output to confirm required argument order"],"exampleFix":"// before\n$ mnemopi delete abc\nError: invalid memory id: abc\n// after\n$ mnemopi delete 42","handlingStrategy":"validation","validationCode":"const id = process.argv[3];\nif (!/^\\d+$/.test(id)) {\n  process.stderr.write(`Error: invalid memory id: ${id}\\n`);\n  process.exit(2);\n}","typeGuard":null,"tryCatchPattern":"import { CliError } from \"@oh-my-pi/metaharness/mnemopi\";\ntry {\n  await cli.run(process.argv);\n} catch (err) {\n  if (err instanceof CliError) {\n    process.stderr.write(`${err.message}\\n`);\n    process.exit(err.exitCode ?? 2);\n  }\n  throw err;\n}","preventionTips":["Validate numeric arguments before passing them to the CLI","Look up valid memory ids with list/search before update or delete","Script defensively: check exit codes (2 = usage/argument error)"],"tags":["cli","argument-validation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}