From 0a00244913f7db7706e8542a1d5fce637357f53c Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 18 Mar 2025 00:10:10 +1100 Subject: [PATCH] chore(gui-client): improve error message when serde fails (#8461) Resolves: #8441 --- rust/gui-client/src-common/src/auth.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/rust/gui-client/src-common/src/auth.rs b/rust/gui-client/src-common/src/auth.rs index 778a890d6..7623a30a2 100644 --- a/rust/gui-client/src-common/src/auth.rs +++ b/rust/gui-client/src-common/src/auth.rs @@ -28,8 +28,13 @@ pub enum Error { PathWrong, #[error("Couldn't read session file: {0}")] ReadFile(std::io::Error), - #[error("Could not (de)serialize session data")] - Serde, + #[error("Could not serialize session data")] + SerializeSession(#[source] serde_json::Error), + #[error("Could not deserialize session data ({json})")] + DeserializeSession { + source: serde_json::Error, + json: String, + }, #[error("State in server response doesn't match state in client request")] StatesDontMatch, #[error("Couldn't write session file: {0}")] @@ -212,7 +217,7 @@ impl Auth { save_file( &session_data_path()?, serde_json::to_string(session) - .map_err(|_| Error::Serde)? + .map_err(Error::SerializeSession)? .as_bytes(), )?; Ok(()) @@ -248,8 +253,9 @@ impl Auth { Err(e) => return Err(Error::ReadFile(e)), }; match std::fs::read_to_string(session_data_path()?) { - Ok(x) => { - session = serde_json::from_str(&x).map_err(|_| Error::Serde)?; + Ok(json) => { + session = serde_json::from_str(&json) + .map_err(|source| Error::DeserializeSession { source, json })?; } Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} Err(e) => return Err(Error::ReadFile(e)),