can1357/oh-my-pi · error · CliError
Error: ${message}
Error message
Error: ${message} What it means
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.
Source
Thrown at packages/mnemopi/src/cli.ts:46
readonly exitCode = 2,
) {
super(message);
this.name = "CliError";
}
}
type CommandHandler = (args: readonly string[], context?: CliContext) => number | Promise<number>;
function out(context: CliContext | undefined, text = ""): void {
(context?.stdout ?? Bun.stdout).write(`${text}\n`);
}
function err(context: CliContext | undefined, text = ""): void {
(context?.stderr ?? Bun.stderr).write(`${text}\n`);
}
function fail(message: string, exitCode = 2): never {
throw new CliError(`Error: ${message}`, exitCode);
}
function usage(message: string): never {
throw new CliError(message, 2);
}
function parseFloatArg(value: string, name: string): number {
const parsed = Number(value);
if (!Number.isFinite(parsed)) fail(`${name} must be a number: ${value}`);
return parsed;
}
function parseIntArg(value: string, name: string): number {
if (!/^[+-]?\d+$/.test(value)) fail(`${name} must be an integer: ${value}`);
const parsed = Number(value);
if (!Number.isSafeInteger(parsed)) fail(`${name} must be an integer: ${value}`);
return parsed;
}View on GitHub (pinned to 9690622007)
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
Example fix
// before $ mnemopi delete abc Error: invalid memory id: abc // after $ mnemopi delete 42
Defensive patterns
Strategy: validation
Validate before calling
const id = process.argv[3];
if (!/^\d+$/.test(id)) {
process.stderr.write(`Error: invalid memory id: ${id}\n`);
process.exit(2);
} Try / catch
import { CliError } from "@oh-my-pi/metaharness/mnemopi";
try {
await cli.run(process.argv);
} catch (err) {
if (err instanceof CliError) {
process.stderr.write(`${err.message}\n`);
process.exit(err.exitCode ?? 2);
}
throw err;
} Prevention
- 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)
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- unknown file type: {value}
- invalid size: {value}
- 2
- invalid --block-size argument '{0}'
- invalid --time-style argument {} Possible values are: - [p
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/e81db1ddd5ed787f.
Report an issue: GitHub.