diff --git a/juniper_actix/Cargo.toml b/juniper_actix/Cargo.toml index 1285cc32..ea641096 100644 --- a/juniper_actix/Cargo.toml +++ b/juniper_actix/Cargo.toml @@ -19,7 +19,8 @@ juniper = { version = "0.14.2", path = "../juniper", default-features = false } tokio = { version = "0.2", features = ["time"] } serde = { version = "1.0.75", features = ["derive"] } serde_json = "1.0.24" -failure = "0.1.7" +anyhow = "1.0" +thiserror = "1.0" [dev-dependencies] juniper = { version = "0.14.2", path = "../juniper", features = ["expose-test-schema", "serde_json"] } diff --git a/juniper_warp/Cargo.toml b/juniper_warp/Cargo.toml index d27cf233..80e47500 100644 --- a/juniper_warp/Cargo.toml +++ b/juniper_warp/Cargo.toml @@ -13,7 +13,8 @@ subscriptions = ["juniper_subscriptions"] [dependencies] bytes = "0.5" -failure = "0.1.7" +anyhow = "1.0" +thiserror = "1.0" futures = "0.3.1" juniper = { version = "0.14.2", path = "../juniper", default-features = false } juniper_subscriptions = { path = "../juniper_subscriptions", optional = true } diff --git a/juniper_warp/src/lib.rs b/juniper_warp/src/lib.rs index eea18fef..43fb5845 100644 --- a/juniper_warp/src/lib.rs +++ b/juniper_warp/src/lib.rs @@ -40,14 +40,14 @@ Check the LICENSE file for details. #![deny(warnings)] #![doc(html_root_url = "https://docs.rs/juniper_warp/0.2.0")] -use std::{collections::HashMap, str, sync::Arc}; - +use anyhow::anyhow; use bytes::Bytes; use futures::{FutureExt as _, TryFutureExt}; use juniper::{ http::{GraphQLBatchRequest, GraphQLRequest}, ScalarValue, }; +use std::{collections::HashMap, str, sync::Arc}; use tokio::task; use warp::{body, filters::BoxedFilter, header, http, query, Filter}; @@ -153,9 +153,8 @@ where let handle_post_graphql_request = move |context: CtxT, body: Bytes| { let schema = post_graphql_schema.clone(); async move { - let query = str::from_utf8(body.as_ref()).map_err(|e| { - failure::format_err!("Request body query is not a valid UTF-8 string: {}", e) - })?; + let query = str::from_utf8(body.as_ref()) + .map_err(|e| anyhow!("Request body query is not a valid UTF-8 string: {}", e))?; let req = GraphQLRequest::new(query.into(), None, None); let resp = req.execute(&schema, &context).await; @@ -177,9 +176,8 @@ where let schema = schema.clone(); async move { let req = GraphQLRequest::new( - qry.remove("query").ok_or_else(|| { - failure::format_err!("Missing GraphQL query string in query parameters") - })?, + qry.remove("query") + .ok_or_else(|| anyhow!("Missing GraphQL query string in query parameters"))?, qry.remove("operation_name"), qry.remove("variables") .map(|vs| serde_json::from_str(&vs)) @@ -247,9 +245,8 @@ where let schema = post_graphql_schema.clone(); async move { let res = task::spawn_blocking(move || { - let query = str::from_utf8(body.as_ref()).map_err(|e| { - failure::format_err!("Request body is not a valid UTF-8 string: {}", e) - })?; + let query = str::from_utf8(body.as_ref()) + .map_err(|e| anyhow!("Request body is not a valid UTF-8 string: {}", e))?; let req = GraphQLRequest::new(query.into(), None, None); let resp = req.execute_sync(&schema, &context); @@ -276,7 +273,7 @@ where let res = task::spawn_blocking(move || { let req = GraphQLRequest::new( qry.remove("query").ok_or_else(|| { - failure::format_err!("Missing GraphQL query string in query parameters") + anyhow!("Missing GraphQL query string in query parameters") })?, qry.remove("operation_name"), qry.remove("variables") @@ -314,7 +311,7 @@ pub struct JoinError(task::JoinError); impl warp::reject::Reject for JoinError {} -fn build_response(response: Result<(Vec, bool), failure::Error>) -> http::Response> { +fn build_response(response: Result<(Vec, bool), anyhow::Error>) -> http::Response> { match response { Ok((body, is_ok)) => http::Response::builder() .status(if is_ok { 200 } else { 400 }) @@ -434,7 +431,7 @@ pub mod subscriptions { websocket: warp::ws::WebSocket, coordinator: Arc>, context: CtxT, - ) -> impl Future> + Send + ) -> impl Future> + Send where Query: juniper::GraphQLTypeAsync + Send + 'static, Query::TypeInfo: Send + Sync, @@ -462,7 +459,7 @@ pub mod subscriptions { sink_rx .map_err(move |e| { got_close_signal2.store(true, Ordering::Relaxed); - failure::format_err!("Websocket error: {}", e) + anyhow!("Websocket error: {}", e) }) .try_fold((), move |_, msg| { let coordinator = coordinator.clone(); @@ -478,9 +475,9 @@ pub mod subscriptions { let msg = msg .to_str() - .map_err(|_| failure::format_err!("Non-text messages are not accepted"))?; + .map_err(|_| anyhow!("Non-text messages are not accepted"))?; let request: WsPayload = serde_json::from_str(msg) - .map_err(|e| failure::format_err!("Invalid WsPayload: {}", e))?; + .map_err(|e| anyhow!("Invalid WsPayload: {}", e))?; match request.type_name.as_str() { "connection_init" => {} @@ -501,10 +498,10 @@ pub mod subscriptions { if let Some(ref payload) = request.payload { if payload.query.is_none() { - return Err(failure::format_err!("Query not found")); + return Err(anyhow!("Query not found")); } } else { - return Err(failure::format_err!("Payload not found")); + return Err(anyhow!("Payload not found")); } tokio::task::spawn(async move {