@@ -7,6 +7,7 @@ import { formatErrorMessage as formatError, runCommandWithRuntime } from "../cli
77import { hasExplicitOptions } from "../command-options.js" ;
88import { isDoctorMachineOutput } from "../doctor-output-mode.js" ;
99import { formatCliJsonFailure } from "../failure-output.js" ;
10+ import { exitCliAfterOutput } from "../one-shot-exit.js" ;
1011import { setCommandJsonMode } from "./json-mode.js" ;
1112
1213const STATE_SQLITE_CONFLICTING_OPTION_NAMES = [
@@ -32,13 +33,13 @@ const STATE_SQLITE_CONFLICTING_OPTION_NAMES = [
3233 "only" ,
3334] as const ;
3435
35- function exitDoctorError ( message : string , json : boolean ) : void {
36+ function exitDoctorError ( message : string , json : boolean ) : never {
3637 if ( json ) {
3738 defaultRuntime . writeJson ( formatCliJsonFailure ( message ) ) ;
3839 } else {
3940 defaultRuntime . error ( message ) ;
4041 }
41- defaultRuntime . exit ( 2 ) ;
42+ exitCliAfterOutput ( defaultRuntime , 2 ) ;
4243}
4344
4445/** Register maintenance commands that inspect or mutate local OpenClaw state. */
@@ -151,7 +152,7 @@ export function registerMaintenanceCommands(program: Command) {
151152 ) ;
152153 }
153154 if ( lintMode ) {
154- await runCommandWithRuntime (
155+ return await runCommandWithRuntime (
155156 defaultRuntime ,
156157 async ( ) => {
157158 const { runDoctorLintCli } = await import ( "../../commands/doctor-lint.js" ) ;
@@ -164,11 +165,10 @@ export function registerMaintenanceCommands(program: Command) {
164165 allowExec : Boolean ( opts . allowExec ) ,
165166 deep : Boolean ( opts . deep ) ,
166167 } ) ;
167- defaultRuntime . exit ( jsonImpliesLint ? 0 : exitCode ) ;
168+ exitCliAfterOutput ( defaultRuntime , jsonImpliesLint ? 0 : exitCode ) ;
168169 } ,
169170 ( err ) => exitDoctorError ( formatError ( err ) , opts . json === true || ! process . stdout . isTTY ) ,
170171 ) ;
171- return ;
172172 }
173173 await runCommandWithRuntime (
174174 defaultRuntime ,
@@ -201,7 +201,7 @@ export function registerMaintenanceCommands(program: Command) {
201201 sessionSqliteGithubIssue : Boolean ( opts . githubIssue ) ,
202202 json : Boolean ( opts . json ) ,
203203 } ) ;
204- defaultRuntime . exit ( 0 ) ;
204+ exitCliAfterOutput ( defaultRuntime , 0 ) ;
205205 } ,
206206 opts . json ? ( err : unknown ) => exitDoctorError ( formatError ( err ) , true ) : undefined ,
207207 ) ;
@@ -223,7 +223,7 @@ export function registerMaintenanceCommands(program: Command) {
223223 if ( opts . json === true && opts . run === true ) {
224224 return exitDoctorError ( "triage --json cannot be combined with --run." , true ) ;
225225 }
226- await runCommandWithRuntime (
226+ return await runCommandWithRuntime (
227227 defaultRuntime ,
228228 async ( ) => {
229229 const { triageCommand } = await import ( "../../commands/triage.js" ) ;
@@ -350,8 +350,7 @@ function parseDoctorStateSqliteMode(value: unknown, json: boolean): "compact" |
350350 if ( value === undefined || value === "compact" ) {
351351 return value ;
352352 }
353- exitDoctorError ( "Invalid --state-sqlite mode. Use compact." , json ) ;
354- throw new Error ( "unreachable" ) ;
353+ return exitDoctorError ( "Invalid --state-sqlite mode. Use compact." , json ) ;
355354}
356355
357356function parseDoctorSessionSqliteMode (
@@ -370,9 +369,8 @@ function parseDoctorSessionSqliteMode(
370369 ) {
371370 return value ;
372371 }
373- exitDoctorError (
372+ return exitDoctorError (
374373 "Invalid --session-sqlite mode. Use dry-run, import, validate, inspect, compact, restore, or recover." ,
375374 json ,
376375 ) ;
377- throw new Error ( "unreachable" ) ;
378376}
0 commit comments