fastly 0.6.0-beta1

Fastly Compute@Edge API
Documentation
//! Error-handling utilities.

pub use crate::request::SendError;
pub use anyhow::{anyhow, bail, ensure, Error};

#[derive(Debug, thiserror::Error)]
pub enum NewError {
    #[error("invalid HTTP header name")]
    InvalidHeaderName,
    #[error("invalid HTTP header value")]
    InvalidHeaderValue,
    #[error("invalid HTTP method")]
    InvalidMethod,
    #[error("error parsing URL: {0}")]
    UrlParseError(#[from] url::ParseError),
}

impl From<std::convert::Infallible> for NewError {
    fn from(_: std::convert::Infallible) -> Self {
        unreachable!()
    }
}

impl From<http::header::InvalidHeaderName> for NewError {
    fn from(_: http::header::InvalidHeaderName) -> Self {
        Self::InvalidHeaderName
    }
}

impl From<http::header::InvalidHeaderValue> for NewError {
    fn from(_: http::header::InvalidHeaderValue) -> Self {
        Self::InvalidHeaderValue
    }
}

impl From<http::method::InvalidMethod> for NewError {
    fn from(_: http::method::InvalidMethod) -> Self {
        Self::InvalidMethod
    }
}

/// Insufficient buffer size error.
///
/// This is thrown by methods like [`RequestHandle::get_header_names`][get_header_names] or
/// [`RequestHandle::get_header_values`][get_header_values] if a value was larger than the provided
/// maximum size.
///
/// This error is used to inform a user that they can try a multi-value hostcall again, using a
/// larger buffer.
///
/// [get_header_names]: ../request/struct.RequestHandle.html#method.get_header_names
/// [get_header_values]: ../request/struct.RequestHandle.html#method.get_header_values
#[derive(Copy, Clone, Debug, PartialEq, Eq, thiserror::Error)]
#[error("insufficient buffer size {buf_size}; value requires {needed_buf_size} bytes")]
pub struct BufferSizeError {
    /// The buffer size.
    ///
    /// This is to help make nicer error messages.
    pub buf_size: usize,
    pub needed_buf_size: usize,
}

impl BufferSizeError {
    /// Create a new [`BufferSizeError`](struct.BufferSizeError.html).
    pub(crate) fn new(buf_size: usize, needed_buf_size: usize) -> Self {
        Self {
            buf_size,
            needed_buf_size,
        }
    }
}