Skip to content

Commit

Permalink
chore: greatly improved error handling in state
Browse files Browse the repository at this point in the history
This approach avoids many of the possible panics.
  • Loading branch information
joamag committed Aug 2, 2024
1 parent 06f3dd0 commit 3943b02
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 145 deletions.
18 changes: 17 additions & 1 deletion crates/common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
//! This module contains the [`Error`] enum, which is used to represent
//! errors that can occur within Boytacean domain.

use std::fmt::{self, Display, Formatter};
use std::{
fmt::{self, Display, Formatter},
io,
string::FromUtf8Error,
};

/// Top level enum for error handling within Boytacean.
///
Expand Down Expand Up @@ -37,3 +41,15 @@ impl Display for Error {
write!(f, "{}", self.description())
}
}

impl From<io::Error> for Error {
fn from(_error: io::Error) -> Self {
Error::CustomError(String::from("IO error"))
}
}

impl From<FromUtf8Error> for Error {
fn from(_error: FromUtf8Error) -> Self {
Error::CustomError(String::from("From UTF8 error"))
}
}
Loading

0 comments on commit 3943b02

Please sign in to comment.