use thiserror::Error;
use fastly::http::request::SendError;
#[derive(Error, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum ESIError {
#[error("invalid request URL provided: `{0}`")]
InvalidRequestUrl(String),
#[error("error sending request: {0}")]
RequestError(#[from] SendError),
#[error("received unexpected status code for fragment `{url}`: {status}")]
UnexpectedStatus { url: String, status: u16 },
#[error("unexpected end of document")]
UnexpectedEndOfDocument,
#[error("writer error: {0}")]
WriterError(#[from] std::io::Error),
#[error("failed to create a regular expression")]
RegexError(#[from] regex::Error),
#[error("failed to execute a function: `{0}`")]
FunctionError(String),
#[error("variable assignment error: `{0}`")]
VariableError(String),
#[error("fragment request error: {0}")]
FragmentRequestError(String),
#[error("parse error: {0}")]
ParseError(String),
#[error("expression evaluation error: {0}")]
ExpressionError(String),
#[error("infinite loop detected after {iterations} iterations (buffer len: {buffer_len}, eof: {eof})")]
InfiniteLoop {
iterations: usize,
buffer_len: usize,
eof: bool,
},
#[error("invalid fragment configuration: {0}")]
InvalidFragmentConfig(String),
#[error("internal error: {0}")]
InternalError(String),
}
pub type Result<T> = std::result::Result<T, ESIError>;