#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum PickerError {
#[error("platform file-picker error: {message}")]
Platform {
message: String,
},
#[error("operation not supported on this platform: {operation}")]
Unsupported {
operation: String,
},
#[error("internal synchronisation error: {message}")]
Internal {
message: String,
},
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum AccessError {
#[error("file access permission has been revoked")]
PermissionRevoked,
#[error("I/O error: {source}")]
Io {
#[from]
source: std::io::Error,
},
#[error("invalid file descriptor returned by platform")]
InvalidDescriptor,
#[error("platform access error: {message}")]
Platform {
message: String,
},
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum TokenParseError {
#[error("invalid base64 encoding: {message}")]
InvalidBase64 {
message: String,
},
#[error("invalid JSON in token: {message}")]
InvalidJson {
message: String,
},
#[error("unknown token variant: {variant}")]
UnknownVariant {
variant: String,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn picker_error_platform_displays_message() {
let err = PickerError::Platform {
message: "dialog failed".into(),
};
let msg = err.to_string();
assert!(!msg.is_empty(), "display string must not be empty");
assert!(msg.contains("dialog failed"));
}
#[test]
fn picker_error_unsupported_displays_message() {
let err = PickerError::Unsupported {
operation: "save".into(),
};
let msg = err.to_string();
assert!(!msg.is_empty());
assert!(msg.contains("save"));
}
#[test]
fn picker_error_internal_displays_message() {
let err = PickerError::Internal {
message: "mutex poisoned".into(),
};
let msg = err.to_string();
assert!(!msg.is_empty());
assert!(msg.contains("mutex poisoned"));
}
#[test]
fn access_error_permission_revoked_displays_message() {
let err = AccessError::PermissionRevoked;
assert!(!err.to_string().is_empty());
}
#[test]
fn access_error_io_displays_message() {
let err = AccessError::Io {
source: std::io::Error::new(std::io::ErrorKind::NotFound, "gone"),
};
assert!(!err.to_string().is_empty());
}
#[test]
fn access_error_invalid_descriptor_displays_message() {
let err = AccessError::InvalidDescriptor;
assert!(!err.to_string().is_empty());
}
#[test]
fn access_error_platform_displays_message() {
let err = AccessError::Platform {
message: "fd error".into(),
};
let msg = err.to_string();
assert!(!msg.is_empty());
assert!(msg.contains("fd error"));
}
#[test]
fn token_parse_error_base64_displays_message() {
let err = TokenParseError::InvalidBase64 {
message: "bad padding".into(),
};
let msg = err.to_string();
assert!(!msg.is_empty());
assert!(msg.contains("bad padding"));
}
#[test]
fn token_parse_error_json_displays_message() {
let err = TokenParseError::InvalidJson {
message: "unexpected EOF".into(),
};
let msg = err.to_string();
assert!(!msg.is_empty());
assert!(msg.contains("unexpected EOF"));
}
#[test]
fn token_parse_error_unknown_variant_displays_message() {
let err = TokenParseError::UnknownVariant {
variant: "FuturePlatform".into(),
};
let msg = err.to_string();
assert!(!msg.is_empty());
assert!(msg.contains("FuturePlatform"));
}
}