Skip to content

Commit 5501748

Browse files
authored
Merge pull request #319 from graphql-rust/error-lib
Switch all examples and crates to anyhow
2 parents a55c7a4 + 9b3b685 commit 5501748

File tree

15 files changed

+44
-51
lines changed

15 files changed

+44
-51
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ A typed GraphQL client library for Rust.
6868
)]
6969
pub struct UnionQuery;
7070

71-
fn perform_my_query(variables: union_query::Variables) -> Result<(), failure::Error> {
71+
fn perform_my_query(variables: union_query::Variables) -> Result<(), anyhow::Error> {
7272

7373
// this is the important line
7474
let request_body = UnionQuery::build_query(variables);

examples/github/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Tom Houlé <[email protected]>"]
55
edition = "2018"
66

77
[dev-dependencies]
8-
failure = "*"
8+
anyhow = "*"
99
graphql_client = { path = "../../graphql_client" }
1010
serde = "^1.0"
1111
reqwest = "^0.9"

examples/github/examples/github.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use failure::*;
1+
use anyhow::*;
22
use graphql_client::*;
33
use log::*;
44
use prettytable::*;
@@ -27,15 +27,15 @@ struct Env {
2727
github_api_token: String,
2828
}
2929

30-
fn parse_repo_name(repo_name: &str) -> Result<(&str, &str), failure::Error> {
30+
fn parse_repo_name(repo_name: &str) -> Result<(&str, &str), anyhow::Error> {
3131
let mut parts = repo_name.split('/');
3232
match (parts.next(), parts.next()) {
3333
(Some(owner), Some(name)) => Ok((owner, name)),
3434
_ => Err(format_err!("wrong format for the repository name param (we expect something like facebook/graphql)"))
3535
}
3636
}
3737

38-
fn main() -> Result<(), failure::Error> {
38+
fn main() -> Result<(), anyhow::Error> {
3939
dotenv::dotenv().ok();
4040
env_logger::init();
4141

examples/hasura/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Mark Catley <[email protected]>"]
55
edition = "2018"
66

77
[dev-dependencies]
8-
failure = "*"
8+
anyhow = "*"
99
graphql_client = { path = "../../graphql_client" }
1010
serde = "1.0"
1111
serde_derive = "1.0"

examples/hasura/examples/hasura.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Timestamptz = String;
1414
)]
1515
struct UpsertIssue;
1616

17-
fn main() -> Result<(), failure::Error> {
17+
fn main() -> Result<(), anyhow::Error> {
1818
use upsert_issue::{IssuesUpdateColumn::*, *};
1919
dotenv::dotenv().ok();
2020
env_logger::init();

graphql_client/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ edition = "2018"
1111

1212
[dependencies]
1313
doc-comment = "^0.3"
14-
failure = { version = "0.1", optional = true }
14+
anyhow = { version = "1.0", optional = true }
15+
thiserror = { version = "1.0", optional = true }
1516
graphql_query_derive = { path = "../graphql_query_derive", version = "0.9.0" }
1617
serde_json = "1.0"
1718
serde = { version = "^1.0.78", features = ["derive"] }
@@ -56,7 +57,8 @@ wasm-bindgen-test = "^0.2"
5657

5758
[features]
5859
web = [
59-
"failure",
60+
"anyhow",
61+
"thiserror",
6062
"futures",
6163
"js-sys",
6264
"log",

graphql_client/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ doc_comment::doctest!("../../README.md");
3939
/// )]
4040
/// struct StarWarsQuery;
4141
///
42-
/// fn main() -> Result<(), failure::Error> {
42+
/// fn main() -> Result<(), anyhow::Error> {
4343
/// use graphql_client::GraphQLQuery;
4444
///
4545
/// let variables = star_wars_query::Variables {
@@ -130,7 +130,7 @@ impl Display for PathFragment {
130130
/// # something: i32
131131
/// # }
132132
/// #
133-
/// # fn main() -> Result<(), failure::Error> {
133+
/// # fn main() -> Result<(), anyhow::Error> {
134134
/// use graphql_client::*;
135135
///
136136
/// let body: Response<ResponseData> = serde_json::from_value(json!({
@@ -247,7 +247,7 @@ impl Display for Error {
247247
/// # dogs: Vec<Dog>,
248248
/// # }
249249
/// #
250-
/// # fn main() -> Result<(), failure::Error> {
250+
/// # fn main() -> Result<(), anyhow::Error> {
251251
/// use graphql_client::Response;
252252
///
253253
/// let body: Response<ResponseData> = serde_json::from_value(json!({

graphql_client/src/web.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
//! [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen).
33
44
use crate::*;
5-
use failure::*;
65
use futures::{Future, IntoFuture};
76
use log::*;
87
use std::collections::HashMap;
8+
use thiserror::*;
99
use wasm_bindgen::{JsCast, JsValue};
1010
use wasm_bindgen_futures::JsFuture;
1111

@@ -24,33 +24,33 @@ pub struct Client {
2424
/// All the ways a request can go wrong.
2525
///
2626
/// not exhaustive
27-
#[derive(Debug, Fail, PartialEq)]
27+
#[derive(Debug, Error, PartialEq)]
2828
pub enum ClientError {
2929
/// The body couldn't be built
30-
#[fail(display = "Request body is not a valid string")]
30+
#[error("Request body is not a valid string")]
3131
Body,
3232
/// An error caused by window.fetch
33-
#[fail(display = "Network error")]
33+
#[error("Network error")]
3434
Network(String),
3535
/// Error in a dynamic JS cast that should have worked
36-
#[fail(display = "JS casting error")]
36+
#[error("JS casting error")]
3737
Cast,
3838
/// No window object could be retrieved
39-
#[fail(
40-
display = "No Window object available - the client works only in a browser (non-worker) context"
39+
#[error(
40+
"No Window object available - the client works only in a browser (non-worker) context"
4141
)]
4242
NoWindow,
4343
/// Response shape does not match the generated code
44-
#[fail(display = "Response shape error")]
44+
#[error("Response shape error")]
4545
ResponseShape,
4646
/// Response could not be converted to text
47-
#[fail(display = "Response conversion to text failed (Response.text threw)")]
47+
#[error("Response conversion to text failed (Response.text threw)")]
4848
ResponseText,
4949
/// Exception thrown when building the request
50-
#[fail(display = "Error building the request")]
50+
#[error("Error building the request")]
5151
RequestError,
5252
/// Other JS exception
53-
#[fail(display = "Unexpected JS exception")]
53+
#[error("Unexpected JS exception")]
5454
JsException,
5555
}
5656

graphql_client_cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ name = "graphql-client"
1212
path = "src/main.rs"
1313

1414
[dependencies]
15-
failure = "^0.1"
15+
anyhow = "1.0"
1616
reqwest = "^0.9"
1717
graphql_client = { version = "0.9.0", path = "../graphql_client" }
1818
graphql_client_codegen = { path = "../graphql_client_codegen/", version = "0.9.0" }

graphql_client_cli/src/generate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use failure::*;
1+
use anyhow::*;
22
use graphql_client_codegen::{
33
generate_module_token_stream, CodegenMode, GraphQLClientCodegenOptions,
44
};
@@ -19,7 +19,7 @@ pub(crate) struct CliCodegenParams {
1919
pub output_directory: Option<PathBuf>,
2020
}
2121

22-
pub(crate) fn generate_code(params: CliCodegenParams) -> Result<(), failure::Error> {
22+
pub(crate) fn generate_code(params: CliCodegenParams) -> Result<()> {
2323
let CliCodegenParams {
2424
variables_derives,
2525
response_derives,
@@ -59,7 +59,7 @@ pub(crate) fn generate_code(params: CliCodegenParams) -> Result<(), failure::Err
5959
options.set_deprecation_strategy(deprecation_strategy);
6060
}
6161

62-
let gen = generate_module_token_stream(query_path.clone(), &schema_path, options)?;
62+
let gen = generate_module_token_stream(query_path.clone(), &schema_path, options).map_err(|fail| fail.compat())?;
6363

6464
let generated_code = gen.to_string();
6565
let generated_code = if cfg!(feature = "rustfmt") && !no_formatting {

0 commit comments

Comments
 (0)