nanocoai/nanoclaw · error
${def.name} id is required
Error message
${def.name} id is required What it means
Thrown by genericGet in src/cli/crud.ts when a `<resource> get` command is invoked without an --id value. Every generic get handler requires the row's id (the resource's idColumn) to locate the record. This is a usage error from the ncl dispatcher, not a DB failure.
Source
Thrown at src/cli/crud.ts:220
if (column) {
filters.push(`${k} = ?`);
params.push(coerceListFilter(column, v));
}
}
const where = filters.length > 0 ? ` WHERE ${filters.join(' AND ')}` : '';
params.push(limit);
// Newest first: without an ORDER BY the LIMIT silently hides the most
// recently inserted rows once a table outgrows it (bit `sessions list`
// past 200 sessions — a just-created session was invisible).
return getDb().all(`SELECT ${cols} FROM ${def.table}${where} ORDER BY ${listOrder(def)} LIMIT ?`, ...params);
};
}
function genericGet(def: ResourceDef) {
const cols = visibleColumns(def).join(', ');
return async (args: Record<string, unknown>) => {
const id = args.id as string;
if (!id) throw new Error(`${def.name} id is required`);
const row = await getDb().get(`SELECT ${cols} FROM ${def.table} WHERE ${def.idColumn} = ?`, id);
if (!row) throw new Error(`${def.name} not found: ${id}`);
return row;
};
}
function genericCreate(def: ResourceDef) {
return async (args: Record<string, unknown>) => {
const values: Record<string, unknown> = {};
// Pass 1: generated columns + explicit caller args only. Static defaults
// wait until after resolveDefaults so the hook sees exactly what the
// caller provided and a static default never pre-empts context-aware
// resolution.
for (const col of def.columns) {
if (col.generated) {
if (col.name === def.idColumn) {
values[col.name] = randomUUID();View on GitHub (pinned to 294ef2aee8)
Solutions
- Pass the id: `ncl <resource> get --id <value>`
- If you meant to browse, use `ncl <resource> list`
- Guard scripts: check the id variable is non-empty before invoking ncl
Example fix
# before ncl groups get # after ncl groups get --id my-group
Defensive patterns
Strategy: validation
Validate before calling
if (!id || !id.trim()) { console.error('id required'); process.exit(1); } Type guard
function hasId(args: Record<string, unknown>): args is { id: string } {
return typeof args.id === 'string' && args.id.length > 0;
} Try / catch
try { await nclGet(id) } catch (e) { if ((e as Error).message.endsWith('id is required')) printUsage(); else throw e; } Prevention
- Always resolve the id via list before calling get
- Reject empty id variables early in shell scripts
When it happens
Trigger: Running `ncl <resource> get` with no --id, or with --id set to an empty string (e.g. `--id ""` from an unset shell variable).
Common situations: Shell scripts passing $ID when the variable is empty; assuming get without id lists rows (use `list` instead).
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- --${col.name.replace(/_/g, '-')} is required
- ${def.name} not found: ${id}
- ${col.name} must be one of: ${col.enum.join(', ')}
- nothing to update — provide at least one of: ${updatableCols
- --folder is required
AI-assisted analysis of nanocoai/nanoclaw@294ef2aee8 (2026-08-28).
Data as JSON: /api/errors/20df3882159c71bc.
Report an issue: GitHub.