From 041a6e51cb37508838436034d5730efc0ae88c25 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Thu, 9 Apr 2026 08:21:35 -1000 Subject: [PATCH] fix: validate required CLI params before calling handler gbrain get with no args now shows "Usage: gbrain get " instead of leaking a raw Postgres driver error (UNDEFINED_VALUE). Co-Authored-By: Claude Opus 4.6 (1M context) --- src/cli.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/cli.ts b/src/cli.ts index 42f3d0f..48223cc 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -69,6 +69,18 @@ async function main() { const engine = await connectEngine(); try { const params = parseOpArgs(op, subArgs); + + // Validate required params before calling handler + for (const [key, def] of Object.entries(op.params)) { + if (def.required && params[key] === undefined) { + const cliName = op.cliHints?.name || op.name; + const positional = op.cliHints?.positional || []; + const usage = positional.map(p => `<${p}>`).join(' '); + console.error(`Usage: gbrain ${cliName} ${usage}`); + process.exit(1); + } + } + const ctx = makeContext(engine, params); const result = await op.handler(ctx, params); const output = formatResult(op.name, result);