Skip to content

SDK version 0.9.0 fails under axum example #261

@glacion

Description

@glacion

Hi, long story short, cargo check works on cloudevents-sdk = { git = "https://github.com/cloudevents/sdk-rust", features = ["axum"] } and 0.8.0 but fails on 0.9.0

cargo.toml:

[package]
name = "event"
version = "0.1.0"
edition = "2021"

[dependencies]
axum = "^0.8"
http = "^1.1"
tokio = { version = "^1", features = ["full"] }
tracing = "^0.1"
tracing-subscriber = "^0.3"
tower-http = { version = "^0.6", features = ["trace"] }
cloudevents-sdk = { version = "0.9.0", features = ["axum"] }

same for edition 2024.
main.rs is as it is on the (https://github.com/cloudevents/sdk-rust/blob/main/example-projects/axum-example/src/main.rs)[example].

encountered error message is as follows:

cargo check
    Blocking waiting for file lock on package cache
    Updating crates.io index
    Blocking waiting for file lock on package cache
     Locking 1 package to latest compatible version
    Updating cloudevents-sdk v0.8.0 -> v0.9.0
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
    Checking cloudevents-sdk v0.9.0
error[E0277]: `?` couldn't convert the error to `StatusCode`
  --> /home/glacion/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cloudevents-sdk-0.9.0/src/binding/axum/extract.rs:26:11
   |
21 |           let body = axum::body::to_bytes(body, usize::MAX).await.map_err(|e| {
   |  ____________________--------------------------------------------_-
   | |                    |
   | |                    this can't be annotated with `?` because it has type `Result<_, axum::Error>`
22 | |             Response::builder()
23 | |                 .status(StatusCode::INTERNAL_SERVER_ERROR)
24 | |                 .body(axum::body::Body::from(e.to_string()))
25 | |                 .unwrap()
26 | |         })?;
   | |          -^ the trait `From<Response<Body>>` is not implemented for `StatusCode`
   | |__________|
   |            this can't be annotated with `?` because it has type `Result<_, Response<Body>>`
   |
   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
   = help: the trait `From<Response<Body>>` is not implemented for `StatusCode`
           but trait `From<&StatusCode>` is implemented for it
   = help: for that trait implementation, expected `&StatusCode`, found `Response<Body>`

error[E0308]: mismatched types
  --> /home/glacion/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cloudevents-sdk-0.9.0/src/binding/axum/extract.rs:28:9
   |
18 |       async fn from_request(req: Request, _state: &S) -> Result<Self, StatusCode> {
   |                                                          ------------------------ expected `std::result::Result<event::Event, StatusCode>` because of return type
...
28 | /         to_event(&parts.headers, body.to_vec()).map_err(|e| {
29 | |             Response::builder()
30 | |                 .status(StatusCode::BAD_REQUEST)
31 | |                 .body(axum::body::Body::from(e.to_string()))
32 | |                 .unwrap()
33 | |         })
   | |__________^ expected `Result<Event, StatusCode>`, found `Result<Event, Response<Body>>`
   |
   = note: expected enum `std::result::Result<_, StatusCode>`
              found enum `std::result::Result<_, Response<Body>>`

error[E0271]: expected `impl Future<Output = Result<Event, StatusCode>>` to be a future that resolves to `Result<Event, Response<Body>>`, but it resolves to `Result<Event, StatusCode>`
  --> /home/glacion/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cloudevents-sdk-0.9.0/src/binding/axum/extract.rs:18:5
   |
18 |     async fn from_request(req: Request, _state: &S) -> Result<Self, StatusCode> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<Event, Response<Body>>`, found `Result<Event, StatusCode>`
   |
   = note: expected enum `std::result::Result<_, Response<Body>>`
              found enum `std::result::Result<_, StatusCode>`
note: required by a bound in `FromRequest::from_request::{anon_assoc#0}`
  --> /home/glacion/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/axum-core-0.5.5/src/extract/mod.rs:88:22
   |
88 |     ) -> impl Future<Output = Result<Self, Self::Rejection>> + Send;
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `FromRequest::from_request::{anon_assoc#0}`

Some errors have detailed explanations: E0271, E0277, E0308.
For more information about an error, try `rustc --explain E0271`.
error: could not compile `cloudevents-sdk` (lib) due to 3 previous errors

please let me know if you need further details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions