Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

738 B
Raw Blame
use std::{error::Error, fmt};

#[derive(Debug)]
pub enum BoundedJsonError {
    LimitExceeded { limit: usize },
    Serialization(serde_json::Error),
}

impl fmt::Display for BoundedJsonError {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::LimitExceeded { limit } => {
                write!(formatter, "serialized JSON exceeds {limit} bytes")
            }
            Self::Serialization(error) => error.fmt(formatter),
        }
    }
}

impl Error for BoundedJsonError {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        match self {
            Self::LimitExceeded { .. } => None,
            Self::Serialization(error) => Some(error),
        }
    }
}