Skip to content

doctest: Fix regression after upgrade of reqwest to 0.10. #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 20, 2020

Conversation

siedentop
Copy link

This was introduced in #350. Besides this, my thanks for upgrading
reqwest. The old version cost me some time yesterday.

I do not know why CI did not catch this. Maybe something for the maintainers to
take a look at. Or I made a mistake in my setup.

Below is the error I got:

---- /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/doc-comment-0.3.3/src/lib.rs - (line 228) stdout ----
error[E0433]: failed to resolve: use of undeclared type or module `reqwest`
  --> /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/doc-comment-0.3.3/src/lib.rs:245:27
   |
20 |     let client = reqwest::Client::new();
   |                           ^^^^^^ not found in `reqwest`
   |
help: consider importing this struct
   |
3  | use graphql_client::web::Client;
   |

error: aborting due to previous error

This was introduced in graphql-rust#350. Besides this, my thanks for upgrading
reqwest. The old version cost me some time yesterday.
@siedentop
Copy link
Author

CC: @boxdot , @tomhoule (as you were both involved in #350).

@siedentop
Copy link
Author

Might make sense to provide some CHANGELOG info, how to upgrade to the newest version.

The diagnostics are pretty good (it says "use await") but it bears repeating.

Upgrading to the newest version of graphql_client requires that send() and json() become send().await and json().await.

error[E0277]: the `?` operator can only be applied to values that implement `Try`
   --> src/main.rs:101:23
    |
101 |           let mut res = client
    |  _______________________^
102 | |             .post("https://api.github.com/graphql")
103 | |             .bearer_auth(&github_api_token)
104 | |             .json(&q)
105 | |             .send()?;
    | |____________________^ the `?` operator cannot be applied to type `impl futures::Future`
    |
    = help: the trait `Try` is not implemented for `impl futures::Future`
    = note: required by `into_result`
help: consider using `.await` here

@siedentop
Copy link
Author

siedentop commented Nov 18, 2020

Two more regressions

  • Github example does not work anymore. This worked fine on macOS on tag v0.9.0, but not on latest master (9160417).
  • My personal example fails with a tokio runtime panic. I'm trying to create a minimal example. And while tokio runtime issues are not the purview of this crate, the issue only appears after upgrading graphql-client.
❯ cargo run --example github graphql-rust/graphql-client

    Updating crates.io index
   Compiling pin-project-internal v1.0.2
   Compiling graphql-introspection-query v0.1.0 (/Users/user/src/tmp/graphql-client/graphql-introspection-query)
   Compiling graphql_client_codegen v0.9.0 (/Users/user/src/tmp/graphql-client/graphql_client_codegen)
   Compiling graphql_query_derive v0.9.0 (/Users/user/src/tmp/graphql-client/graphql_query_derive)
   Compiling pin-project v1.0.2
   Compiling futures-util v0.3.8
   Compiling graphql_client v0.9.0 (/Users/user/src/tmp/graphql-client/graphql_client)
   Compiling h2 v0.2.7
   Compiling hyper v0.13.9
   Compiling hyper-tls v0.4.3
   Compiling reqwest v0.10.8
   Compiling graphql_query_github_example v0.1.0 (/Users/user/src/tmp/graphql-client/examples/github)
    Finished dev [unoptimized + debuginfo] target(s) in 35.09s
     Running `target/debug/examples/github graphql-rust/graphql-client`
Error: error decoding response body: expected value at line 2 column 1

Caused by:
    expected value at line 2 column 1

EDIT:

Here's the Response I get. Note that the only difference is the git ref I use.

Error: Response: Response { url: Url { scheme: "https", host: Some(Domain("api.github.com")), port: None, path: "/graphql", query: None, fragment: None }, status: 403, headers: {"cache-control": "no-cache", "connection": "close", "content-type": "text/html; charset=utf-8", "strict-transport-security": "max-age=31536000", "x-content-type-options": "nosniff", "x-frame-options": "deny", "x-xss-protection": "1; mode=block", "content-security-policy": "default-src 'none'; style-src 'unsafe-inline'"} }

Diff to generate the context (in github.rs):

-    let response_body: Response<repo_view::ResponseData> = res.json()?;
+    let context = format!("Response: {:?}", res);
+    let response_body: Response<repo_view::ResponseData> = res.json().context(context)?;

@siedentop
Copy link
Author

Reproducer is here: https://github.com/siedentop/graphql-reproducer

Error I get with that:

 ~/d/graphql-reproducer   main  cargo run                                                                                                 4866ms  Wed Nov 18 15:23:33 2020
   Compiling graphql-reproducer v0.1.0 (/Users/user/devel/graphql-reproducer)
    Finished dev [unoptimized + debuginfo] target(s) in 8.01s
     Running `target/debug/graphql-reproducer`
The application panicked (crashed).
Message:  not currently running on the Tokio runtime.
Location: /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.23/src/runtime/handle.rs:118

Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

@boxdot
Copy link
Contributor

boxdot commented Nov 19, 2020

Thank you for investigating the regression!

Reproducer is here: https://github.com/siedentop/graphql-reproducer

You have a mismatch of reqwest version 0.10.8 and tokio version 0.3. This version of reqwest still runs on tokio 0.2. Changing to tokio 0.2 fixed the panic.

I am still looking into the expected value at line 2 column 1 problem.

@siedentop
Copy link
Author

siedentop commented Nov 19, 2020

Changing to tokio 0.2 fixed the panic.
Thank you! This is great.

I am still looking into the expected value at line 2 column 1 problem.

EDIT: The below is wrong. My mistake, keeping the \\n and not de-escaping it to \n.

I found it. It's newline characters in the serialization.

Repro with curl: curl -v -H "Authorization: bearer $GITHUB_API_TOKEN" -X POST -d @minimal.broken.json https://api.github.com/graphql

❯ cat minimal.broken.json
{
  "variables": { "owner": "siedentop", "name": "git-quickfix" },
  "query": "query {   viewer {\\n     login  }\\n}"
}
❯ cat minimal.json
{
  "variables": { "owner": "siedentop", "name": "git-quickfix" },
  "query": "query {viewer { login  }}"
}

@siedentop
Copy link
Author

siedentop commented Nov 20, 2020

Found it. (For real this time ;) )

Put this in to debug: let body = res.bytes()?; debug!("Bytes: {:#?}", body);

Bytes: b"\r\nRequest forbidden by administrative rules. Please make sure your request has a User-Agent header (http://developer.github.com/v3/#user-agent-required). Check https://developer.github.com for other possible causes.\r\n"


How to fix your code: Use user_agent().

    // Old version: let client = reqwest::blocking::Client::new()
    let client = reqwest::blocking::Client::builder()
        .user_agent("graphql-rust/0.9.0")
        .build()?;

Release notes in reqwest:

https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md
[section 0.10.0]
Change to no longer send a default User-Agent header. Add one via ClientBuilder::user_agent().

Also some minor cleanup (Table and using `error_for_status()`)
@siedentop
Copy link
Author

@tomhoule , IMO ready to merge.

@boxdot please review.

@tomhoule, one question: Would you be open to a second example very similar to this, that also used tokio to do multiple requests in parallel (while sharing the client connection)?

No idea whence this came. ¯\_(ツ)_/¯ Wasn't present in graphql-rust#350 and this
branch does  not touch anything there.
Copy link
Member

@tomhoule tomhoule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@tomhoule
Copy link
Member

@siedentop I would wait for #338 before adding more examples with custom clients. Also I am a bit reluctant to add code when there is so little resources for maintenance. But I would definitely accept a good PR :)

@boxdot
Copy link
Contributor

boxdot commented Nov 20, 2020

Thank you for fixing the regression introduced by my MR.

@tomhoule tomhoule merged commit eddbcd1 into graphql-rust:master Nov 20, 2020
@siedentop siedentop deleted the bugfix/fix-regression-on-350 branch November 20, 2020 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants