Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error fallback variant #1429

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions sdk/src/types/block/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ pub enum Error {
DuplicateOutputChain(ChainId),
InvalidField(&'static str),
NullDelegationValidatorId,
#[cfg(feature = "std")]
Fallback(FallbackError),
}

#[cfg(feature = "std")]
Expand Down Expand Up @@ -375,6 +377,7 @@ impl fmt::Display for Error {
Self::DuplicateOutputChain(chain_id) => write!(f, "duplicate output chain {chain_id}"),
Self::InvalidField(field) => write!(f, "invalid field: {field}"),
Self::NullDelegationValidatorId => write!(f, "null delegation validator ID"),
Self::Fallback(err) => write!(f, "error: {err}"),
}
}
}
Expand All @@ -390,3 +393,24 @@ impl From<Infallible> for Error {
match error {}
}
}

#[cfg(feature = "std")]
#[derive(Debug)]
pub struct FallbackError(pub(crate) Box<dyn std::error::Error + Send + Sync>);

#[cfg(feature = "std")]
impl PartialEq for FallbackError {
fn eq(&self, _: &Self) -> bool {
false
}
}

#[cfg(feature = "std")]
impl Eq for FallbackError {}

#[cfg(feature = "std")]
impl fmt::Display for FallbackError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
Loading