diff options
| author | pml68 <contact@pml68.me> | 2024-10-30 03:00:17 +0100 |
|---|---|---|
| committer | pml68 <contact@pml68.me> | 2024-10-30 03:00:17 +0100 |
| commit | 87e745b8e60225a789b51d5011fa620051c4cfbe (patch) | |
| tree | 6bf3cede25ee428939500038439508415d636f45 /iced_builder/src/error.rs | |
| parent | feat: implement very basic playground (diff) | |
| download | iced-builder-87e745b8e60225a789b51d5011fa620051c4cfbe.tar.gz | |
feat: add error dialogs, windows manifest
Diffstat (limited to 'iced_builder/src/error.rs')
| -rw-r--r-- | iced_builder/src/error.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/iced_builder/src/error.rs b/iced_builder/src/error.rs new file mode 100644 index 0000000..5bf41b1 --- /dev/null +++ b/iced_builder/src/error.rs @@ -0,0 +1,61 @@ +use rfd::{MessageButtons, MessageDialog, MessageLevel}; +use std::io; +use thiserror::Error; + +#[derive(Debug, Clone, Error)] +pub enum Error { + #[error("An I/O error accured: {0}")] + IOError(String), + #[error("A Serde error accured: {0}")] + SerdeError(String), + #[error("A RustFmt error accured: {0}")] + FormatError(String), + #[error("The element tree contains no matching element")] + NonExistentElement, + #[error("The file dialog has been closed without selecting a valid option")] + DialogClosed, + #[error("{0}")] + Other(String), +} + +impl From<io::Error> for Error { + fn from(value: io::Error) -> Self { + Self::IOError(value.to_string()) + } +} + +impl From<serde_json::Error> for Error { + fn from(value: serde_json::Error) -> Self { + Self::SerdeError(value.to_string()) + } +} + +impl From<rust_format::Error> for Error { + fn from(value: rust_format::Error) -> Self { + Self::FormatError(value.to_string()) + } +} + +impl From<&'static str> for Error { + fn from(value: &'static str) -> Self { + Self::Other(value.to_owned()) + } +} + +pub fn error_dialog(description: impl Into<String>) { + MessageDialog::new() + .set_level(MessageLevel::Error) + .set_buttons(MessageButtons::Ok) + .set_title("Oops! Something went wrong.") + .set_description(description) + .show(); +} + +pub fn warning_dialog(title: impl Into<String>, description: impl Into<String>) { + MessageDialog::new() + .set_level(MessageLevel::Warning) + .set_buttons(MessageButtons::Ok) + .set_title(title) + .set_description(description) + .show(); +} |
