#![deny(missing_docs)]
#![deny(unused_crate_dependencies)]
use fuel_core_storage::Error as StorageError;
use fuel_core_types::services::executor::Error as ExecutorError;
use std::{
array::TryFromSliceError,
io::ErrorKind,
};
#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error("error performing serialization or deserialization")]
Codec,
#[error("Failed to initialize chain")]
ChainAlreadyInitialized,
#[error("Chain is not yet initialized")]
ChainUninitialized,
#[error("Invalid database version, expected {expected:#x}, found {found:#x}")]
InvalidDatabaseVersion {
found: u32,
expected: u32,
},
#[error(transparent)]
Other(#[from] anyhow::Error),
}
impl From<Error> for std::io::Error {
fn from(e: Error) -> Self {
std::io::Error::new(ErrorKind::Other, e)
}
}
impl From<Error> for StorageError {
fn from(e: Error) -> Self {
StorageError::DatabaseError(Box::new(e))
}
}
impl From<TryFromSliceError> for Error {
fn from(e: TryFromSliceError) -> Self {
Self::Other(anyhow::anyhow!(e))
}
}
impl From<Error> for ExecutorError {
fn from(e: Error) -> Self {
ExecutorError::StorageError(Box::new(StorageError::from(e)))
}
}
#[cfg(test)]
fuel_core_trace::enable_tracing!();