1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::parser::Rule;
use http::Method;
use snafu::Snafu;

pub(crate) type Result<T, E = Error> = std::result::Result<T, E>;

#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
pub enum Error {
    #[snafu(display("Failed to parse input string with pest rules"))]
    ParseRule {
        #[snafu(source(from(pest::error::Error<Rule>, Box::new)))]
        source: Box<pest::error::Error<Rule>>,
    },
    #[snafu(display("Expect a {label}. But value is {value}"))]
    ExpectValue { label: &'static str, value: String },
    #[snafu(display("Failed to parse HTTP method"))]
    ParseMethod { source: http::method::InvalidMethod },
    #[snafu(display("Unsupported HTTP method: {method}"))]
    UnsupportedMethod { method: Method },
    #[snafu(display("URL is required for http call"))]
    RequiredUrl,
    #[snafu(display("Value is required"))]
    RequiredValue,
    #[snafu(display("Unsupported type: {value}"))]
    UnsupportedType { value: String },
    #[snafu(display("Unsupported attr {name}: {value}"))]
    UnsupportedAttr { name: String, value: String },

    #[snafu(display("Failed to parse URL"))]
    ParseUrl { source: http::uri::InvalidUri },
    #[snafu(display("Failed to parse header name"))]
    ParseHeaderName {
        source: http::header::InvalidHeaderName,
    },
    #[snafu(display("Failed to parse header value"))]
    ParseHeaderValue {
        source: http::header::InvalidHeaderValue,
    },

    #[snafu(display("Failed to render request template"))]
    Render { source: minijinja::Error },
}