mirror of
https://github.com/mii443/wasmer.git
synced 2025-08-23 00:45:32 +00:00
Using this command, fixed format argument inlining to improve readability, and fix a few minor related styling issues like trailing commas in a single line. ``` cargo clippy --all-targets --workspace --exclude wasmer-cli --exclude wasmer-swift -- -D clippy::uninlined_format_args ```
37 lines
1.0 KiB
Rust
37 lines
1.0 KiB
Rust
/// One or multiple errors returned by the GraphQL API.
|
|
// Mainly exists to implement [`std::error::Error`].
|
|
#[derive(Debug)]
|
|
pub struct GraphQLApiFailure {
|
|
pub errors: Vec<cynic::GraphQlError>,
|
|
}
|
|
|
|
impl GraphQLApiFailure {
|
|
pub fn from_errors(
|
|
msg: impl Into<String>,
|
|
errors: Option<Vec<cynic::GraphQlError>>,
|
|
) -> anyhow::Error {
|
|
let msg = msg.into();
|
|
if let Some(errs) = errors {
|
|
if !errs.is_empty() {
|
|
let err = GraphQLApiFailure { errors: errs };
|
|
return anyhow::Error::new(err).context(msg);
|
|
}
|
|
}
|
|
anyhow::anyhow!("{msg} - query did not return any data")
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for GraphQLApiFailure {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
let errs = self
|
|
.errors
|
|
.iter()
|
|
.map(|err| err.to_string())
|
|
.collect::<Vec<_>>()
|
|
.join(", ");
|
|
write!(f, "GraphQL API failure: {errs}")
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for GraphQLApiFailure {}
|