bitcoin_internals/error/mod.rs
1// SPDX-License-Identifier: CC0-1.0
2
3//! # Error
4//!
5//! Error handling macros and helpers.
6
7#[cfg(not(creusot))]
8pub mod input_string;
9mod parse_error;
10
11#[cfg(not(creusot))]
12pub use input_string::InputString;
13
14/// Formats error.
15///
16/// If `std` feature is OFF appends error source (delimited by `: `). We do this because
17/// `e.source()` is only available in std builds, without this macro the error source is lost for
18/// no-std builds.
19#[macro_export]
20macro_rules! write_err {
21 ($writer:expr, $string:literal $(, $args:expr)*; $source:expr) => {
22 {
23 #[cfg(feature = "std")]
24 {
25 let _ = &$source; // Prevents clippy warnings.
26 write!($writer, $string $(, $args)*)
27 }
28 #[cfg(not(feature = "std"))]
29 {
30 write!($writer, concat!($string, ": {}") $(, $args)*, $source)
31 }
32 }
33 }
34}