fix(client): report runtime errors on disconnect

The Windows client sends a best-effort disconnect control message after the
runtime loop exits. That message previously always said `client shutting down`,
even when the loop ended because TAP I/O, relay event handling, or relay-route
verification failed.

Preserve the returned error, but include its chain in the disconnect message so
the relay log records why the client left during manual MVP testing. Clean exits
still report the original shutdown text.

Test Plan:
- cargo fmt --check
- cargo test -p lanparty-client-win
- cargo test --workspace
- cargo clippy --workspace --all-targets -- -D warnings
- git diff --check
- git diff --cached --check

Refs: MVP Windows client diagnostics
This commit is contained in:
2026-05-22 08:52:46 +02:00
parent d4b29346d7
commit 5f567b4320
+23 -1
View File
@@ -212,13 +212,21 @@ async fn main() -> Result<()> {
let _ = config.tap_instance_id; let _ = config.tap_instance_id;
#[cfg(not(windows))] #[cfg(not(windows))]
let run_result = run_client(&session).await; let run_result = run_client(&session).await;
session.shutdown("client shutting down").await; let shutdown_message = client_shutdown_message(&run_result);
session.shutdown(&shutdown_message).await;
#[cfg(windows)] #[cfg(windows)]
drop(relay_route_pin); drop(relay_route_pin);
run_result run_result
} }
fn client_shutdown_message(run_result: &Result<()>) -> String {
match run_result {
Ok(()) => "client shutting down".to_owned(),
Err(error) => format!("client shutting down after error: {error:#}"),
}
}
#[cfg(windows)] #[cfg(windows)]
fn ensure_supported_platform() -> Result<()> { fn ensure_supported_platform() -> Result<()> {
Ok(()) Ok(())
@@ -1274,6 +1282,20 @@ mod tests {
assert!(error.to_string().contains("does not match tunnel identity")); assert!(error.to_string().contains("does not match tunnel identity"));
} }
#[test]
fn reports_runtime_errors_in_shutdown_message() {
assert_eq!(
client_shutdown_message(&Ok(())),
"client shutting down".to_owned()
);
let error = anyhow::anyhow!("route pin changed").context("bridge stopped");
assert_eq!(
client_shutdown_message(&Err(error)),
"client shutting down after error: bridge stopped: route pin changed".to_owned()
);
}
#[test] #[test]
fn formats_client_diagnostics_status_line() { fn formats_client_diagnostics_status_line() {
let diagnostics = ClientDiagnostics::new( let diagnostics = ClientDiagnostics::new(