mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
chore(gui-client): improve error message when serde fails (#8461)
Resolves: #8441
This commit is contained in:
@@ -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)),
|
||||
|
||||
Reference in New Issue
Block a user