Skip to main content

ifx_sdk/
error.rs

1//! Planner / ix builder errors.
2
3use std::fmt;
4
5#[derive(Clone, Debug, PartialEq, Eq)]
6pub enum ScratchError {
7    IndexCapReached { index: u8, cap: u16 },
8    TapeExceeded { end_cursor: u32, tape_len: u32, record_len: u32 },
9    InvalidTapeLen,
10    InvalidFrameId,
11    BindingType(String),
12    Encode(String),
13    /// Frame account decode failed (integration / debug only).
14    FrameDecode(String),
15    /// Frame tape read failed (integration / debug only).
16    FrameRead(String),
17}
18
19impl fmt::Display for ScratchError {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            Self::IndexCapReached { index, cap } => {
23                write!(
24                    f,
25                    "scratch binding index cap reached (binding #{index} >= {cap}); increase tapeLen or reset"
26                )
27            }
28            Self::TapeExceeded {
29                end_cursor,
30                tape_len,
31                record_len,
32            } => write!(
33                f,
34                "scratch would exceed tape (needs +{record_len} B, end cursor {end_cursor} > tapeLen {tape_len}); reset or use a larger Frame"
35            ),
36            Self::InvalidTapeLen => write!(f, "tape_len out of range"),
37            Self::InvalidFrameId => write!(f, "frame_id must be 32 bytes"),
38            Self::BindingType(msg) => write!(f, "{msg}"),
39            Self::Encode(msg) => write!(f, "encode failed: {msg}"),
40            Self::FrameDecode(msg) => write!(f, "frame decode: {msg}"),
41            Self::FrameRead(msg) => write!(f, "frame read: {msg}"),
42        }
43    }
44}
45
46impl std::error::Error for ScratchError {}