[READ-ONLY] Mirror of https://github.com/SantaClaas/gigit. git client
Something went wrong. Try again.
Rust
at ref-filter
1234567891011121314151617181920212223242526272829303132333435363738394041424344use serde::{ser::SerializeStruct, Serialize, Serializer};
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]pub enum Error { #[error(transparent)] Git(#[from] gigit_git::Error),
#[error("no repository is open with id {0}")] UnknownRepository(String),
#[error("the repository worker stopped unexpectedly")] WorkerStopped,
#[error("could not start a thread for the repository")] SpawnThread(#[source] std::io::Error),}
impl Error { /// A stable tag the frontend can branch on, so it never has to match on /// human-readable message text. fn kind(&self) -> &'static str { match self { Self::Git(_) => "git", Self::UnknownRepository(_) => "unknownRepository", Self::WorkerStopped => "workerStopped", Self::SpawnThread(_) => "spawnThread", } }}
/// Tauri requires command errors to be serializable. Errors cross as a kind and/// a message rather than a bare string, so the UI can react to the kind and/// still have something to show.impl Serialize for Error { fn serialize<S: Serializer>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error> { let mut state = serializer.serialize_struct("Error", 2)?; state.serialize_field("kind", self.kind())?; state.serialize_field("message", &self.to_string())?; state.end() }}