Add InternalError variant to StateDatabaseError
This change adds an InternalError variant to the StateDatabaseError.
use std::error::Error;
use std::fmt;
+use crate::error::InternalError;
use crate::protos::ProtoConversionError;
use cbor::decoder::DecodeError;
use cbor::encoder::EncodeError;
@@ -30,6 +31,7 @@ pub enum StateDatabaseError {
DeserializationError(DecodeError),
SerializationError(EncodeError),
ChangeLogEncodingError(String),
+ InternalError(InternalError),
InvalidRecord,
InvalidHash(String),
InvalidChangeLogIndex(String),
@@ -51,6 +53,7 @@ impl fmt::Display for StateDatabaseError {
StateDatabaseError::ChangeLogEncodingError(ref msg) => {
write!(f, "Unable to serialize change log entry: {}", msg)
}
+ StateDatabaseError::InternalError(ref err) => f.write_str(&err.to_string()),
StateDatabaseError::InvalidRecord => write!(f, "A node was malformed"),
StateDatabaseError::InvalidHash(ref msg) => {
write!(f, "The given hash is invalid: {}", msg)
@@ -76,6 +79,7 @@ impl Error for StateDatabaseError {
StateDatabaseError::DeserializationError(ref err) => Some(err),
StateDatabaseError::SerializationError(ref err) => Some(err),
StateDatabaseError::ChangeLogEncodingError(_) => None,
+ StateDatabaseError::InternalError(ref err) => Some(err),
StateDatabaseError::InvalidRecord => None,
StateDatabaseError::InvalidHash(_) => None,
StateDatabaseError::InvalidChangeLogIndex(_) => None,
@@ -123,3 +127,9 @@ impl From<ProtoConversionError> for StateDatabaseError {
StateDatabaseError::ProtobufConversionError(err)
}
}
+
+impl From<InternalError> for StateDatabaseError {
+ fn from(err: InternalError) -> Self {
+ StateDatabaseError::InternalError(err)
+ }
+}
