#[macro_export]
#[doc(hidden)]
macro_rules! reportable_error {
( $($arg:tt)* ) => ({
$crate::error::ArconResult::Err($crate::error::Error::ReportableBug { msg: format!($($arg)*) })
})
}
pub mod source;
pub mod timer;
use arcon_state::error::ArconStateError;
use arrow::error::ArrowError;
use snafu::{Backtrace, Snafu};
use std::{io, io::ErrorKind};
pub type ArconResult<T> = std::result::Result<T, Error>;
pub type StateResult<T> = std::result::Result<T, ArconStateError>;
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("Unsupported operation {}", msg))]
Unsupported { msg: String },
#[snafu(display(
"Unexpected bug {} please report at https://github.com/cda-group/arcon",
msg
))]
ReportableBug { msg: String },
#[snafu(display("An IO error occured {}", error))]
Io { error: io::Error },
#[snafu(display("Unexpected data corruption {} with backtrace {:?}", msg, backtrace))]
Corruption { msg: String, backtrace: Backtrace },
}
impl From<io::Error> for Error {
#[inline]
fn from(io_error: io::Error) -> Self {
Error::Io { error: io_error }
}
}
impl From<Error> for io::Error {
fn from(error: Error) -> io::Error {
use self::Error::*;
match error {
Io { error } => error,
Unsupported { ref msg } => io::Error::new(
ErrorKind::InvalidInput,
format!("operation not supported: {:?}", msg),
),
ReportableBug { ref msg } => io::Error::new(
ErrorKind::Other,
format!(
"unexpected bug! please report this bug at github.com/cda-group/arcon {:?}",
msg
),
),
Corruption { msg, .. } => io::Error::new(
ErrorKind::InvalidData,
format!("corruption encountered: {:?}", msg),
),
}
}
}
impl From<ArconStateError> for Error {
fn from(error: ArconStateError) -> Self {
let msg = error.to_string();
match error {
ArconStateError::IO { source, .. } => Error::Io { error: source },
ArconStateError::FixedBytesSerializationError { backtrace, .. } => {
Error::Corruption { msg, backtrace }
}
ArconStateError::FixedBytesDeserializationError { backtrace, .. } => {
Error::Corruption { msg, backtrace }
}
ArconStateError::ProtobufDecodeError { backtrace, .. } => {
Error::Corruption { msg, backtrace }
}
ArconStateError::ProtobufEncodeError { backtrace, .. } => {
Error::Corruption { msg, backtrace }
}
#[cfg(feature = "rocksdb")]
ArconStateError::RocksError { .. } => Error::ReportableBug { msg },
ArconStateError::SledError { .. } => Error::ReportableBug { msg },
_ => Error::Unsupported { msg },
}
}
}
impl From<ArrowError> for Error {
fn from(error: ArrowError) -> Self {
let msg = error.to_string();
match error {
ArrowError::IoError(err) => Error::Io {
error: io::Error::new(ErrorKind::Other, err),
},
_ => Error::Unsupported { msg },
}
}
}