-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use { | ||
serde::{ | ||
ser::SerializeStruct, | ||
Serialize, | ||
Serializer, | ||
}, | ||
std::io::ErrorKind, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct Io { | ||
kind: ErrorKind, | ||
code: Option<i32>, | ||
msg: String, | ||
} | ||
|
||
impl Serialize for Io { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
let mut state = serializer.serialize_struct("Io", 3)?; | ||
state.serialize_field("kind", &self.kind.to_string().replace(' ', "_"))?; | ||
state.serialize_field("code", &self.code)?; | ||
state.serialize_field("msg", &self.msg)?; | ||
state.end() | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Default)] | ||
pub struct Unknown { | ||
msg: String, | ||
} | ||
|
||
impl<T: std::error::Error> From<T> for Unknown { | ||
fn from(value: T) -> Self { | ||
Self { | ||
msg: value.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl From<std::io::Error> for Io { | ||
fn from(value: std::io::Error) -> Self { | ||
let code = value.raw_os_error(); | ||
|
||
Self { | ||
kind: value.kind(), | ||
msg: value.to_string(), | ||
code, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum IpcError { | ||
Io(Box<Io>), | ||
Unknown(Box<Unknown>), | ||
} | ||
|
||
impl<T: std::error::Error> From<T> for IpcError { | ||
default fn from(value: T) -> Self { | ||
Self::Unknown(Box::new(value.into())) | ||
} | ||
} | ||
|
||
impl From<std::io::Error> for IpcError { | ||
fn from(value: std::io::Error) -> Self { | ||
Self::Io(Box::new(value.into())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
#![feature(specialization)] | ||
|
||
mod lookup; | ||
pub(crate) mod error; | ||
|
||
pub use lookup::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
use std::path::Path; | ||
use { | ||
crate::error::IpcError, | ||
std::path::Path, | ||
}; | ||
|
||
#[tauri::command] | ||
pub async fn lookup_versions(path: &Path) -> Result<Vec<lookup::VersionOverview>, String> { | ||
lookup::lookup_versions(path).await.map_err(|err| err.to_string()) | ||
pub async fn lookup_versions(path: &Path) -> Result<Vec<lookup::VersionOverview>, IpcError> { | ||
Ok(lookup::lookup_versions(path).await?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters