actix / actix-web

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
https://actix.rs
Apache License 2.0
21.6k stars 1.67k forks source link

Logging reports wrong type error #510

Closed lee-b closed 6 years ago

lee-b commented 6 years ago

This might have something to do with how serde tries type promotion and handles failures, but I thought it was worth reporting here first, at least because it's the actix_web::pipeline that creates the log message.

Something strange is going on with the type handling of Path<T>. With the following simple code, almost verbatim from docs:

#[macro_use] extern crate serde_derive;
extern crate actix_web;
extern crate env_logger;
use actix_web::{server, App, Path, Responder, http};
use actix_web::middleware::Logger;

#[derive(Deserialize)]
struct Coord {
    x: i32,
    y: i32,
}

fn greet(coord: Path<Coord>) -> impl Responder {
    format!("Hello, over there at ({},{})!", coord.x, coord.y)
}

fn main() {
    std::env::set_var("RUST_LOG", "actix_web=info");
    env_logger::init();

    server::new(|| {
        App::new()
            .middleware(Logger::default())
            .middleware(Logger::new("%a %{User-Agent}i"))
            .resource("/{x}/{y}", |r| r.method(http::Method::GET).with(greet))
    })

    .bind("127.0.0.1:6767")
    .expect("Can not bind to port 6767")
    .run();
}

Running this with RUST_BACKTRACE=1 RUST_LOG=actix_web=debug cargo run and doing a GET request to /1/3200000000, causes the following log entry:

WARN 2018-09-15T23:45:54Z: actix_web::pipeline: Error occured during request handling: can not parse "3200000000" to a i16

Note how the error is about an i16, yet it CAN parse 32-bit integer values successfully. So it's correctly using an i32 to parse them, but giving the wrong type in the WARN logging.

fafhrd91 commented 6 years ago

thanks for report, fixed in master

dbrgn commented 5 years ago

Somehow this seems to be back on v1.0.0-beta.3 (from crates.io): i32 in the path results in an error message like this:

can not parse "99999999999999999" to a i16