use snafu::Snafu;
use crate::transport::TransportError;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, Snafu)]
#[snafu(module, visibility(pub(crate)))]
#[non_exhaustive]
pub enum Error {
#[snafu(display("the vendored {surface} contract embedded in this build did not parse"))]
VendoredContract {
surface: &'static str,
},
#[snafu(display("the vendored tapes-api contract has no operation {operation:?}"))]
ContractOperation {
operation: String,
},
#[snafu(display(
"the vendored tapes-api contract does not declare parameter {parameter:?} on {operation:?}"
))]
ContractParameter {
operation: String,
parameter: String,
},
#[snafu(display(
"operation {operation:?} requires path parameter {parameter:?} and none was supplied"
))]
ContractPathParameter {
operation: String,
parameter: String,
},
#[snafu(display(
"operation {operation:?} requires {location} parameter {parameter:?} and none was supplied"
))]
ContractRequiredParameter {
operation: String,
parameter: String,
location: &'static str,
},
#[snafu(display("operation {operation:?} {detail}"))]
ContractBody {
operation: String,
detail: &'static str,
},
#[snafu(display("unexpected server contract: {detail}"))]
Contract {
detail: &'static str,
},
#[snafu(display("cassette discovery named a non-relative OpenAPI path {path:?}"))]
SpecPath {
path: String,
},
#[snafu(display("cassette spec used an unusable HTTP method {method:?}"))]
Method {
method: String,
},
#[snafu(display("no cassette named {name:?} is served here"))]
UnknownCassette {
name: String,
},
#[snafu(display("cassette {cassette:?} has no method {method:?}"))]
UnknownMethod {
cassette: String,
method: String,
},
#[snafu(display("could not build the request URL"))]
Url {
source: url::ParseError,
},
#[snafu(display("the base URL cannot be a base for API paths"))]
NotABase,
#[snafu(display("could not reach the tapes API: {source}"))]
Transport {
source: TransportError,
},
#[snafu(display("could not initialize the HTTP client"))]
ClientInit,
#[snafu(display("tapes API returned {status} for {endpoint}: {body}"))]
ApiStatus {
status: u16,
endpoint: String,
body: String,
},
#[snafu(display("could not decode the tapes API response"))]
Decode {
source: serde_json::Error,
},
#[snafu(display("could not read the request body at {path}"))]
BodyFile {
path: String,
source: std::io::Error,
},
#[snafu(display("--body is not valid JSON"))]
InvalidBody {
source: serde_json::Error,
},
#[snafu(display("could not render the request body"))]
RenderBody {
source: serde_json::Error,
},
}