Skip to content

Commit ff75081

Browse files
committed
more plumbing for better errors
1 parent 8d4574c commit ff75081

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

crates/kcserver/src/kernel_session/handshake.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4047
impl 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) => {

crates/kcserver/src/kernel_session/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ impl KernelSession {
190190
self.connection.session_id.clone(),
191191
self.connection.clone(),
192192
self.ws_json_tx.clone(),
193+
None, // shell_used not yet determined
194+
None, // startup_command not yet determined
193195
);
194196

195197
let (path, socket, rx) = handshake_coord.setup_registration_socket().await?;
@@ -287,6 +289,8 @@ impl KernelSession {
287289
self.connection.session_id.clone(),
288290
self.connection.clone(),
289291
self.ws_json_tx.clone(),
292+
coordinator.shell_used.clone(),
293+
coordinator.startup_command.clone(),
290294
);
291295

292296
match handshake_coord

0 commit comments

Comments
 (0)