Skip to main content

bitcoin_primitives/script/
error.rs

1// SPDX-License-Identifier: CC0-1.0
2
3//! Error types for Bitcoin scripts.
4
5use core::convert::Infallible;
6use core::fmt;
7
8use encoding::ByteVecDecoderError;
9use internals::write_err;
10
11#[rustfmt::skip]                // Keep public re-exports separate.
12#[doc(inline)]
13pub use crate::hash_types::{RedeemScriptSizeError, WitnessScriptSizeError};
14#[doc(inline)]
15pub use super::push_bytes::PushBytesError;
16
17/// An error consensus decoding a `ScriptBuf<T>`.
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub struct ScriptBufDecoderError(pub(super) ByteVecDecoderError);
20
21impl From<Infallible> for ScriptBufDecoderError {
22    fn from(never: Infallible) -> Self { match never {} }
23}
24
25impl fmt::Display for ScriptBufDecoderError {
26    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write_err!(f, "decoder error"; self.0) }
27}
28
29#[cfg(feature = "std")]
30impl std::error::Error for ScriptBufDecoderError {
31    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
32}