@@ -20,6 +20,7 @@ use crate::{
2020 connection_file:: ConnectionFile ,
2121 error:: KSError ,
2222 kernel_connection:: KernelConnection ,
23+ kernel_session:: utils:: strip_startup_markers,
2324 registration_file:: RegistrationFile ,
2425 registration_socket:: { HandshakeResult , RegistrationSocket } ,
2526 startup_status:: StartupStatus ,
@@ -35,6 +36,12 @@ pub struct HandshakeCoordinator {
3536
3637 /// Channel to send messages to the WebSocket
3738 ws_json_tx : Sender < WebsocketMessage > ,
39+
40+ /// The shell used for startup (for error reporting)
41+ shell_used : Option < String > ,
42+
43+ /// The startup command/script executed (for error reporting)
44+ startup_command : Option < String > ,
3845}
3946
4047impl HandshakeCoordinator {
@@ -43,11 +50,15 @@ impl HandshakeCoordinator {
4350 session_id : String ,
4451 connection : KernelConnection ,
4552 ws_json_tx : Sender < WebsocketMessage > ,
53+ shell_used : Option < String > ,
54+ startup_command : Option < String > ,
4655 ) -> Self {
4756 Self {
4857 session_id,
4958 connection,
5059 ws_json_tx,
60+ shell_used,
61+ startup_command,
5162 }
5263 }
5364
@@ -271,16 +282,36 @@ impl HandshakeCoordinator {
271282 match startup_status {
272283 Ok ( StartupStatus :: AbnormalExit ( exit_code, output, error) ) => {
273284 // The kernel exited before the handshake could complete
285+
286+ // Strip internal markers from output
287+ let clean_output = strip_startup_markers ( & output) ;
288+
289+ // Build context for the error message
290+ let mut error_context = String :: new ( ) ;
291+ if let Some ( shell) = & self . shell_used {
292+ error_context. push_str ( & format ! ( "Shell: {}\n " , shell) ) ;
293+ }
294+ if let Some ( cmd) = & self . startup_command {
295+ error_context. push_str ( & format ! ( "Startup command: {}\n " , cmd) ) ;
296+ }
297+ error_context. push_str ( "The kernel exited before a connection could be established" ) ;
298+
274299 log:: error!(
275300 "[session {}] Kernel exited during handshake with code {}: {}" ,
276301 self . session_id,
277302 exit_code,
278303 error
279304 ) ;
305+ log:: error!(
306+ "[session {}] Output before exit: \n {}" ,
307+ self . session_id,
308+ clean_output
309+ ) ;
310+
280311 Err ( StartupError {
281312 exit_code : Some ( exit_code) ,
282- output : Some ( output ) ,
283- error : KSError :: ExitedBeforeConnection . to_json ( None ) ,
313+ output : Some ( clean_output ) ,
314+ error : KSError :: ExitedBeforeConnection . to_json ( Some ( error_context ) ) ,
284315 } )
285316 }
286317 Ok ( status) => {
0 commit comments