fcd909830822
report usage errors as JSON on stderr when --json is given, as the document asks (3.0.48)
- time
- 2026-09-24 16:11 UTC · 2 weeks ago
- machine
- koh2
- agent
- claude-opus-5-5
- session
- koh 3 reliability campaign
- parent
- cb84f9ea35c4
↓ koh-fcd90983.tar.gzatlas at this save
files changed5 files
VERSION+1 −1src/cli/cli.v+1 −3src/cli/output.v+8 −1tests/cli_test.v+8 −0v.mod+1 −1src/cli/cli.v+1 −3
@@ -124,9 +124,7 @@124124 return cmd_man(rest)125125 }126126 else {127- eprintln(' koh: unknown command "${argv[1]}"')128- eprintln(' run "koh --help" for the command list')129- return 2127+ return usage_error('unknown command "${argv[1]}" — run "koh --help" for the command list')130128 }131129 }132130 }src/cli/output.v+8 −1
@@ -9,6 +9,7 @@99 module cli1010 1111 import json12+import os1213 import src.fmt1314 1415 pub fn ok(message string) {@@ -36,8 +37,14 @@3637 return 13738 }3839 40+// usage_error reports a mistake in the command line itself. It can happen41+// before the options are parsed, so `--json` is looked for on the raw line.3942 pub fn usage_error(message string) int {40- eprintln(' ${fmt.red(fmt.glyph_fail)} ${message}')43+ if '--json' in os.args {44+ fail_json(message)45+ } else {46+ eprintln(' ${fmt.red(fmt.glyph_fail)} ${message}')47+ }4148 return 24249 }4350 tests/cli_test.v+8 −0
@@ -94,6 +94,14 @@9494 assert run(dir, 'init').code == 19595 assert run(dir, 'unknown-command').code == 29696 assert run(dir, 'unknown-command').err.contains('unknown command')97+ // An agent asking for JSON gets JSON for a usage mistake too, exit 2.98+ for args in [['unknown-command', '--json'], ['save', '--json'],99+ ['save', 'x', '--nope', '--json']] {100+ r2 := run(dir, ...args)101+ assert r2.code == 2102+ assert r2.out == ''103+ assert r2.err.starts_with('{"error":'), r2.err104+ }97105 }98106 99107 fn test_save_checkpoint_and_status() {v.mod+1 −1
@@ -1,6 +1,6 @@11 Module {22 name: 'koh3'3- version: '3.0.47'3+ version: '3.0.48'44 description: 'One SQLite file per repo, one line of history.'55 license: 'MIT'66 }