-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CHORE] Implement thiserror::Error for DaftError and arrow2::Error (#…
…2785) # Overview - implemented `thiserror::Error` for `common::error::DaftError` and `arrow2::error::Error` - removed many `impl From<X> for DaftError` and many `impl From<X> for arrow2::Error`
- Loading branch information
Showing
11 changed files
with
103 additions
and
246 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,113 +1,45 @@ | ||
use std::{ | ||
fmt::{Display, Formatter, Result}, | ||
io, | ||
}; | ||
use thiserror::Error; | ||
|
||
pub type DaftResult<T> = std::result::Result<T, DaftError>; | ||
pub type GenericError = Box<dyn std::error::Error + Send + Sync>; | ||
|
||
#[derive(Debug)] | ||
#[derive(Debug, Error)] | ||
pub enum DaftError { | ||
#[error("DaftError::FieldNotFound {0}")] | ||
FieldNotFound(String), | ||
#[error("DaftError::SchemaMismatch {0}")] | ||
SchemaMismatch(String), | ||
#[error("DaftError::TypeError {0}")] | ||
TypeError(String), | ||
#[error("DaftError::ComputeError {0}")] | ||
ComputeError(String), | ||
ArrowError(String), | ||
#[error("DaftError::ArrowError {0}")] | ||
ArrowError(#[from] arrow2::error::Error), | ||
#[error("DaftError::ValueError {0}")] | ||
ValueError(String), | ||
#[cfg(feature = "python")] | ||
PyO3Error(pyo3::PyErr), | ||
IoError(io::Error), | ||
FileNotFound { | ||
path: String, | ||
source: GenericError, | ||
}, | ||
#[error("DaftError::PyO3Error {0}")] | ||
PyO3Error(#[from] pyo3::PyErr), | ||
#[error("DaftError::IoError {0}")] | ||
IoError(#[from] std::io::Error), | ||
#[error("DaftError::FileNotFound {path}: {source}")] | ||
FileNotFound { path: String, source: GenericError }, | ||
#[error("DaftError::InternalError {0}")] | ||
InternalError(String), | ||
#[error("ConnectTimeout {0}")] | ||
ConnectTimeout(GenericError), | ||
#[error("ReadTimeout {0}")] | ||
ReadTimeout(GenericError), | ||
#[error("ByteStreamError {0}")] | ||
ByteStreamError(GenericError), | ||
#[error("SocketError {0}")] | ||
SocketError(GenericError), | ||
#[error("DaftError::External {0}")] | ||
External(GenericError), | ||
} | ||
|
||
impl std::error::Error for DaftError { | ||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
match self { | ||
DaftError::FieldNotFound(_) | ||
| DaftError::SchemaMismatch(_) | ||
| DaftError::TypeError(_) | ||
| DaftError::ComputeError(_) | ||
| DaftError::ArrowError(_) | ||
| DaftError::ValueError(_) | ||
| DaftError::InternalError(_) => None, | ||
DaftError::IoError(io_error) => Some(io_error), | ||
DaftError::FileNotFound { source, .. } | ||
| DaftError::SocketError(source) | ||
| DaftError::External(source) | ||
| DaftError::ReadTimeout(source) | ||
| DaftError::ConnectTimeout(source) | ||
| DaftError::ByteStreamError(source) => Some(&**source), | ||
#[cfg(feature = "python")] | ||
DaftError::PyO3Error(pyerr) => Some(pyerr), | ||
} | ||
} | ||
} | ||
|
||
impl From<arrow2::error::Error> for DaftError { | ||
fn from(error: arrow2::error::Error) -> Self { | ||
match error { | ||
arrow2::error::Error::Io(_) => DaftError::ByteStreamError(error.into()), | ||
_ => DaftError::ArrowError(error.to_string()), | ||
} | ||
} | ||
} | ||
|
||
impl From<serde_json::Error> for DaftError { | ||
fn from(error: serde_json::Error) -> Self { | ||
DaftError::IoError(error.into()) | ||
} | ||
} | ||
|
||
impl From<io::Error> for DaftError { | ||
fn from(error: io::Error) -> Self { | ||
DaftError::IoError(error) | ||
} | ||
} | ||
|
||
impl From<regex::Error> for DaftError { | ||
fn from(error: regex::Error) -> Self { | ||
DaftError::ValueError(error.to_string()) | ||
} | ||
} | ||
|
||
impl From<std::fmt::Error> for DaftError { | ||
fn from(error: std::fmt::Error) -> Self { | ||
DaftError::ComputeError(error.to_string()) | ||
} | ||
} | ||
|
||
pub type DaftResult<T> = std::result::Result<T, DaftError>; | ||
|
||
impl Display for DaftError { | ||
// `f` is a buffer, and this method must write the formatted string into it | ||
fn fmt(&self, f: &mut Formatter) -> Result { | ||
match self { | ||
Self::FieldNotFound(s) => write!(f, "DaftError::FieldNotFound {s}"), | ||
Self::SchemaMismatch(s) => write!(f, "DaftError::SchemaMismatch {s}"), | ||
Self::TypeError(s) => write!(f, "DaftError::TypeError {s}"), | ||
Self::ComputeError(s) => write!(f, "DaftError::ComputeError {s}"), | ||
Self::ArrowError(s) => write!(f, "DaftError::ArrowError {s}"), | ||
Self::ValueError(s) => write!(f, "DaftError::ValueError {s}"), | ||
Self::InternalError(s) => write!(f, "DaftError::InternalError {s}"), | ||
#[cfg(feature = "python")] | ||
Self::PyO3Error(e) => write!(f, "DaftError::PyO3Error {e}"), | ||
Self::IoError(e) => write!(f, "DaftError::IoError {e}"), | ||
Self::External(e) => write!(f, "DaftError::External {}", e), | ||
Self::FileNotFound { path, source } => { | ||
write!(f, "DaftError::FileNotFound {path}: {source}") | ||
} | ||
Self::ByteStreamError(e) => write!(f, "ByteStreamError: {}", e), | ||
Self::ConnectTimeout(e) => write!(f, "ConnectTimeout: {}", e), | ||
Self::ReadTimeout(e) => write!(f, "ReadTimeout: {}", e), | ||
Self::SocketError(e) => write!(f, "SocketError: {}", e), | ||
} | ||
} | ||
#[error("DaftError::SerdeJsonError {0}")] | ||
SerdeJsonError(#[from] serde_json::Error), | ||
#[error("DaftError::FmtError {0}")] | ||
FmtError(#[from] std::fmt::Error), | ||
#[error("DaftError::RegexError {0}")] | ||
RegexError(#[from] regex::Error), | ||
} |
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
Oops, something went wrong.