smplx_sdk/program/error.rs
1/// Errors that can occur when compiling, preparing, and executing Simplicity programs.
2#[derive(Debug, thiserror::Error)]
3pub enum ProgramError {
4 /// Error thrown when compiling the raw Simplicity program source fails.
5 #[error("Failed to compile Simplicity program: {0}")]
6 Compilation(String),
7
8 /// Error indicating failure while matching or satisfying witness values to the program requirements.
9 #[error("Failed to satisfy witness: {0}")]
10 WitnessSatisfaction(String),
11
12 /// Error indicating pruning the node tree during execution failed safely.
13 #[error("Failed to prune program: {0}")]
14 Pruning(#[from] simplicityhl::simplicity::bit_machine::ExecutionError),
15
16 /// Error thrown when the bit machine cannot be initialized due to complexity or limit restrictions.
17 #[error("Failed to construct a Bit Machine with enough space: {0}")]
18 BitMachineCreation(#[from] simplicityhl::simplicity::bit_machine::LimitError),
19
20 /// Error thrown during bit machine execution due to underlying logical or environment validation errors.
21 #[error("Failed to execute program on the Bit Machine: {0}")]
22 Execution(simplicityhl::simplicity::bit_machine::ExecutionError),
23
24 /// Error indicating an input index points past the bounds of available inputs/UTXOs.
25 #[error("UTXO index {input_index} out of bounds (have {utxo_count} UTXOs)")]
26 UtxoIndexOutOfBounds {
27 /// The requested input index to spend.
28 input_index: usize,
29 /// The actual total number of available UTXOs.
30 utxo_count: usize,
31 },
32
33 /// Error indicating the script pubkey present on the targeted UTXO differs from the expectation.
34 #[error("Script pubkey mismatch: expected hash {expected_hash}, got {actual_hash}")]
35 ScriptPubkeyMismatch {
36 /// The expected CMR (Commitment Merkle Root) hash.
37 expected_hash: String,
38 /// The actual CMR hash present in the script pubkey.
39 actual_hash: String,
40 },
41
42 /// Error thrown when an underlying Elements transaction fails to extract from the PSET wrapper.
43 #[error("Failed to extract tx from pst: {0}")]
44 TxExtraction(#[from] simplicityhl::elements::pset::Error),
45
46 /// Error indicating an array size overflow if the target index exceeds limits.
47 #[error("Input index exceeds u32 maximum: {0}")]
48 InputIndexOverflow(#[from] std::num::TryFromIntError),
49
50 /// Error thrown if the compiled program fails to export or generate valid ABI metadata.
51 #[error("Failed to obtain program witness types: {0}")]
52 ProgramGenAbiMeta(String),
53}