-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 chore: marginally improve error handling
Signed-off-by: Pauline <[email protected]>
- Loading branch information
1 parent
2ca1966
commit 10f17f9
Showing
7 changed files
with
90 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#[derive(thiserror::Error, serde::Serialize, serde::Deserialize, Debug)] | ||
pub enum MoonlightError { | ||
#[error("failed to get windows file lock: {0}")] | ||
WindowsFileLock(String), | ||
#[error("failed to get macos file permission: {0}")] | ||
MacOSNoPermission(String), | ||
#[error("network request failed: {0}")] | ||
NetworkFailed(String), | ||
#[error("unknown error: {0}")] | ||
Unknown(String), | ||
} | ||
|
||
pub type Result<T> = std::result::Result<T, MoonlightError>; | ||
|
||
impl From<std::io::Error> for MoonlightError { | ||
fn from(value: std::io::Error) -> Self { | ||
match (value.raw_os_error(), std::env::consts::OS) { | ||
(Some(32), "windows") => Self::WindowsFileLock(value.to_string()), | ||
(Some(1), "macos") => Self::MacOSNoPermission(value.to_string()), | ||
_ => Self::Unknown(value.to_string()), | ||
} | ||
} | ||
} | ||
|
||
impl From<Box<dyn std::error::Error>> for MoonlightError { | ||
fn from(value: Box<dyn std::error::Error>) -> Self { | ||
Self::Unknown(value.to_string()) | ||
} | ||
} | ||
|
||
impl From<reqwest::Error> for MoonlightError { | ||
fn from(value: reqwest::Error) -> Self { | ||
Self::NetworkFailed(value.to_string()) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod error; | ||
mod installer; | ||
mod util; | ||
pub use error::*; | ||
pub use installer::Installer; | ||
pub use util::*; | ||
pub mod types; |
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
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