@@ -10,6 +10,7 @@ use rust_i18n::{i18n, t};
1010use std:: { io, process:: exit} ;
1111use sysinfo:: { Process , RefreshKind , System , get_current_pid, ProcessRefreshKind } ;
1212use tracing:: { error, info, warn, debug} ;
13+ use util:: flush_and_shutdown_tracing;
1314
1415use crate :: util:: { EXIT_INVALID_INPUT , get_input} ;
1516
@@ -68,6 +69,7 @@ fn main() {
6869 Ok ( merged) => Some ( merged) ,
6970 Err ( err) => {
7071 error ! ( "{}: {err}" , t!( "main.failedMergingParameters" ) ) ;
72+ flush_and_shutdown_tracing ( ) ;
7173 exit ( EXIT_INVALID_INPUT ) ;
7274 }
7375 }
@@ -88,8 +90,10 @@ fn main() {
8890 SubCommand :: Mcp => {
8991 if let Err ( err) = start_mcp_server ( ) {
9092 error ! ( "{}" , t!( "main.failedToStartMcpServer" , error = err) ) ;
93+ flush_and_shutdown_tracing ( ) ;
9194 exit ( util:: EXIT_MCP_FAILED ) ;
9295 }
96+ flush_and_shutdown_tracing ( ) ;
9397 exit ( util:: EXIT_SUCCESS ) ;
9498 }
9599 SubCommand :: Resource { subcommand } => {
@@ -101,13 +105,15 @@ fn main() {
101105 Ok ( json) => json,
102106 Err ( err) => {
103107 error ! ( "JSON: {err}" ) ;
108+ flush_and_shutdown_tracing ( ) ;
104109 exit ( util:: EXIT_JSON_ERROR ) ;
105110 }
106111 } ;
107112 util:: write_object ( & json, output_format. as_ref ( ) , false ) ;
108113 } ,
109114 }
110115
116+ flush_and_shutdown_tracing ( ) ;
111117 exit ( util:: EXIT_SUCCESS ) ;
112118}
113119
@@ -119,15 +125,18 @@ fn ctrlc_handler() {
119125 info ! ( "{}: {}" , t!( "main.foundProcesses" ) , sys. processes( ) . len( ) ) ;
120126 let Ok ( current_pid) = get_current_pid ( ) else {
121127 error ! ( "{}" , t!( "main.failedToGetPid" ) ) ;
128+ flush_and_shutdown_tracing ( ) ;
122129 exit ( util:: EXIT_CTRL_C ) ;
123130 } ;
124131 info ! ( "{}: {}" , t!( "main.currentPid" ) , current_pid) ;
125132 let Some ( current_process) = sys. process ( current_pid) else {
126133 error ! ( "{}" , t!( "main.failedToGetProcess" ) ) ;
134+ flush_and_shutdown_tracing ( ) ;
127135 exit ( util:: EXIT_CTRL_C ) ;
128136 } ;
129137
130138 terminate_subprocesses ( & sys, current_process) ;
139+ flush_and_shutdown_tracing ( ) ;
131140 exit ( util:: EXIT_CTRL_C ) ;
132141}
133142
@@ -192,6 +201,7 @@ fn check_store() {
192201 eprintln ! ( "{}" , t!( "main.storeMessage" ) ) ;
193202 // wait for keypress
194203 let _ = io:: stdin ( ) . read ( & mut [ 0u8 ] ) . unwrap ( ) ;
204+ flush_and_shutdown_tracing ( ) ;
195205 exit ( util:: EXIT_INVALID_ARGS ) ;
196206 }
197207}
0 commit comments