Skip to main content

dash_platform_queries/
error.rs

1//! Errors produced by the transport-free query core.
2
3use dpp::consensus::ConsensusError;
4use dpp::validation::SimpleConsensusValidationResult;
5use dpp::ProtocolError;
6
7/// Error type for the transport-free query core.
8///
9/// `dash-sdk` converts this into its own `Error` via `From`, so code that
10/// moved here from the SDK keeps working behind `?` at its old call sites.
11// Same allowance rs-sdk's Error carries: ProtocolError dominates the size.
12#[allow(clippy::large_enum_variant)]
13#[derive(Debug, thiserror::Error)]
14pub enum Error {
15    /// Query is not configured properly for the target platform version
16    #[error("SDK misconfigured: {0}")]
17    Config(String),
18    /// Drive error
19    #[error("Drive error: {0}")]
20    Drive(#[from] drive::error::Error),
21    /// DPP error
22    #[error("Protocol error: {0}")]
23    Protocol(#[from] ProtocolError),
24}
25
26impl From<ConsensusError> for Error {
27    fn from(value: ConsensusError) -> Self {
28        Self::Protocol(ProtocolError::ConsensusError(Box::new(value)))
29    }
30}
31
32impl From<SimpleConsensusValidationResult> for Error {
33    fn from(value: SimpleConsensusValidationResult) -> Self {
34        value
35            .errors
36            .into_iter()
37            .next()
38            .map(Error::from)
39            .unwrap_or_else(|| {
40                Error::Protocol(ProtocolError::CorruptedCodeExecution(
41                    "state transition structure validation failed without an error".to_string(),
42                ))
43            })
44    }
45}