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

How to enable RUST_BACKTRACE when HTTP 500 Error? #896

Closed micfan closed 5 years ago

micfan commented 5 years ago

Can you give me a hint, thanks.

I got this output, normally here would output the traceback errors, I guess ...

[2019-06-06T09:00:06Z INFO  actix_server::builder] Starting 8 workers
[2019-06-06T09:00:06Z INFO  actix_server::builder] Starting server on 0.0.0.0:3000
[2019-06-06T09:00:17Z INFO  actix_web::middleware::logger] 10.0.0.31:62907 "POST /v1/user/login HTTP/1.1" 500 41 "http://localhost:8000/user/login" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36" 0.002990
fafhrd91 commented 5 years ago

actix does not print backtrace. but it should log errors and response body should contain error body

micfan commented 5 years ago

You're right, got the error message Display by error!():

impl From<Error> for ServiceError {
    fn from(error: Error) -> ServiceError {
        error!("{}", error);
        // Right now we just care about UniqueViolation from diesel
        // But this would be helpful to easily map errors as our app grows
        match error {
            Error::DatabaseError(kind, info) => {
                if let DatabaseErrorKind::UniqueViolation = kind {
                    let message =
                        info.details().unwrap_or_else(|| info.message()).to_string();
                    return ServiceError::BadRequest(message);
                }
                ServiceError::InternalServerError
            }
            _ => ServiceError::InternalServerError,
        }
    }
}
micfan commented 5 years ago

hi, what can I do when the HTTP 500 occured? I only got a 500 error message, but don't konw what happen, my debugger's breakpoint not take effect at all

fafhrd91 commented 5 years ago

you can implement backtrace for your error, actix-web does not support backtrace

micfan commented 5 years ago

ok. For the websocket in actix-web-actors = "1.0.0", where can I set a break point in debugger to inspect when the client connected?

fafhrd91 commented 5 years ago

In your handler

micfan commented 5 years ago

the break point in WS handler can work in the actix/examples.

I deduce that my own handler is not correct, so that the web::resource.to(my_handler) return HTTP 500 error. I will continue find why, thank you!

micfan commented 5 years ago

I still do not know how to dive into Rust for this situation.

But after read the actrix document, the Actor Model concept, I found I lost this line in my WS code:

https://github.com/actix/examples/blob/9c8389e06e75ac704af0ccb91865c321684d8bf0/websocket-chat/src/main.rs#L211

When start this actor, the WS server won't return HTTP 500