Skip to content
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

[Bug] octocrab::Octocrab::request_installation_auth_token fails with status code 411 #463

Closed
phideg opened this issue Oct 2, 2023 · 3 comments

Comments

@phideg
Copy link
Contributor

phideg commented Oct 2, 2023

I'm writing a GitHub app that fails at following code snippet:

    // read issues
    let issue_handler = octocrab.issues(GITHUB_OWNER, GITHUB_REPO);
    let issues = issue_handler
        .list()
        .state(params::State::Open)
        .per_page(10)
        .send()
        .await?
        .take_items();

call stack of error is:

Error: Serde Error: expected value at line 2 column 1
Found at  0 <snafu::backtrace_shim::Backtrace as snafu::GenerateImplicitData>::generate::hf12a34d663f0e574
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/snafu-0.7.5/src/backtrace_shim.rs:15
   snafu::GenerateImplicitData::generate_with_source::h647f062bf6690964
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/snafu-0.7.5/src/lib.rs:1154
 1 <octocrab::error::SerdeSnafu as snafu::IntoError<octocrab::error::Error>>::into_error::h5aadde84b6442c0d
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/octocrab-0.31.0/src/error.rs:23
 2 <core::result::Result<T,E> as snafu::ResultExt<T,E>>::context::hb74aa06b1cbf6eec
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/snafu-0.7.5/src/lib.rs:699
 3 octocrab::map_github_error::{{closure}}::h390244a7a3c433b0
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/octocrab-0.31.0/src/lib.rs:306
 4 octocrab::Octocrab::request_installation_auth_token::{{closure}}::h21aa363dc82eab90
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/octocrab-0.31.0/src/lib.rs:1402
 5 octocrab::Octocrab::execute::{{closure}}::haff4e60098dbb58b
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/octocrab-0.31.0/src/lib.rs:1479
 6 octocrab::Octocrab::_get_with_headers::{{closure}}::h1049d18787c232f6
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/octocrab-0.31.0/src/lib.rs:1256
 7 octocrab::Octocrab::get_with_headers::{{closure}}::h055b89bf78f83ee5
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/octocrab-0.31.0/src/lib.rs:1235
 8 octocrab::Octocrab::get::{{closure}}::h8b9e4e5b0e3da28b
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/octocrab-0.31.0/src/lib.rs:1181
 9 octocrab::api::issues::list::ListIssuesBuilder::send::{{closure}}::h99e00c801406d309
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/octocrab-0.31.0/src/api/issues/list.rs:132
10 octoc::main::{{closure}}::h37ae1894746a2bc3
   /home/ph/git/GitHubAPI-Examples/octoc/src/main.rs:35
11 tokio::runtime::park::CachedParkThread::block_on::{{closure}}::h1b94ed0b8122f758
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/park.rs:282
12 tokio::runtime::coop::with_budget::hc550389b9e9edc63
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/coop.rs:107
   tokio::runtime::coop::budget::hc9432772b23c5cef
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/coop.rs:73
   tokio::runtime::park::CachedParkThread::block_on::h2b2f7d4112eabea7
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/park.rs:282
13 tokio::runtime::context::blocking::BlockingRegionGuard::block_on::hf6cf8e9f03c0da21
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/context/blocking.rs:66
14 tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}::hdb49ed7b612aa685
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/multi_thread/mod.rs:87
15 tokio::runtime::context::runtime::enter_runtime::h890daa6211c2a855
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/context/runtime.rs:65
16 tokio::runtime::scheduler::multi_thread::MultiThread::block_on::h1ea99df985c27bd7
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/multi_thread/mod.rs:86
17 tokio::runtime::runtime::Runtime::block_on::h4ba6da215289277c
   /home/ph/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/runtime.rs:349
18 octoc::main::hd0997659a7555491
   /home/ph/git/GitHubAPI-Examples/octoc/src/main.rs:48
19 core::ops::function::FnOnce::call_once::h2726fcb850d2749b
   /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/ops/function.rs:250
20 std::sys_common::backtrace::__rust_begin_short_backtrace::hf92bccbb18ef6a37
   /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/sys_common/backtrace.rs:135
21 std::rt::lang_start::{{closure}}::h3e86bfc7a660b5ac
   /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/rt.rs:166
22 core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h802b0fdd426a12ca
   /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/ops/function.rs:284
   std::panicking::try::do_call::h2a2f25050efa0cf8
   /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:500
   std::panicking::try::h9ca7f841c0f0e3dd
   /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:464
   std::panic::catch_unwind::h92d42a62587f8121
   /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panic.rs:142
   std::rt::lang_start_internal::{{closure}}::hf1926c7a173d562c
   /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/rt.rs:148
   std::panicking::try::do_call::haac70d88f0cce898
   /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:500
   std::panicking::try::h5c20719e1031e74b
   /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:464
   std::panic::catch_unwind::h9b15b36860d5fe4a
   /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panic.rs:142
   std::rt::lang_start_internal::hf502095b101390bb
   /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/rt.rs:148
23 std::rt::lang_start::hcb880789089b7552
   /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/rt.rs:165
24 main
25 __libc_start_main
26 _start

Caused by:
    expected value at line 2 column 1

The http status code is StatusCode::LENGTH_REQUIRED => (411, LENGTH_REQUIRED, "Length Required");

I figured, that the "bug" is due to the following code line in octocrab/src/lib.rs:1396

        let response = self
            .send(request.body(String::new()).context(HttpSnafu)?)
            .await?;

If I replace String::new() with "{}".to_string() everything works as expected

        let response = self
            .send(request.body("{}".to_string()).context(HttpSnafu)?)
            .await?;
@phideg
Copy link
Contributor Author

phideg commented Oct 2, 2023

used octocrab version is v0.31.0.

@XAMPPRocky
Copy link
Owner

Thank you for your issue! Would you be able to provide your fix as a PR?

phideg pushed a commit to phideg/octocrab that referenced this issue Oct 4, 2023
Fixes issue XAMPPRocky#463.

GitHub REST API endpoints, that use the http POST method, seem to require a `CONTENT-LENGTH` header even if the request body is empty.

This change addresses the issue either by sending an empty JSON document or by explicitly setting the `CONTENT-LENGTH` header as described in following issue:
seanmonstar/reqwest#83
@phideg
Copy link
Contributor Author

phideg commented Oct 5, 2023

PR is open :)

XAMPPRocky pushed a commit that referenced this issue Jan 15, 2024
Fixes issue #463.

GitHub REST API endpoints, that use the http POST method, seem to require a `CONTENT-LENGTH` header even if the request body is empty.

This change addresses the issue either by sending an empty JSON document or by explicitly setting the `CONTENT-LENGTH` header as described in following issue:
seanmonstar/reqwest#83

Co-authored-by: Philipp Degler <philipp.degler@sap.com>
@phideg phideg closed this as completed Mar 3, 2024
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

No branches or pull requests

2 participants