Skip to content

Fix panic on ctry! error #858

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 1 commit into from
Jun 28, 2020
Merged

Fix panic on ctry! error #858

merged 1 commit into from
Jun 28, 2020

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Jun 28, 2020

Before

Website

image

Logs

Jun 28 01:45:10 docsrs cratesfyi[21043]: 2020/06/28 01:45:10 [ERROR] cratesfyi::web: internal server error: Template not found: resp

After

Website

image

Logs

2020/06/27 21:42:48 [ERROR] cratesfyi::web::rustdoc: called cexpect!() on a `None` value
   0: cratesfyi::web::rustdoc::target_redirect_handler
             at src/web/rustdoc.rs:462
   1: core::ops::function::Fn::call
             at /home/joshua/.local/lib/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:72
   2: <F as iron::middleware::Handler>::handle
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/iron-0.5.1/src/middleware/mod.rs:312
   3: <alloc::boxed::Box<dyn iron::middleware::Handler> as iron::middleware::Handler>::handle
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/iron-0.5.1/src/middleware/mod.rs:318
   4: <cratesfyi::web::metrics::RequestRecorder as iron::middleware::Handler>::handle
             at src/web/metrics.rs:192
   5: <alloc::boxed::Box<dyn iron::middleware::Handler> as iron::middleware::Handler>::handle
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/iron-0.5.1/src/middleware/mod.rs:318
   6: <alloc::boxed::Box<dyn iron::middleware::Handler> as iron::middleware::Handler>::handle
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/iron-0.5.1/src/middleware/mod.rs:318
   7: router::router::Router::handle_method
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/router-0.5.1/src/router.rs:199
   8: <router::router::Router as iron::middleware::Handler>::handle
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/router-0.5.1/src/router.rs:212
   9: <alloc::boxed::Box<dyn iron::middleware::Handler> as iron::middleware::Handler>::handle
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/iron-0.5.1/src/middleware/mod.rs:318
  10: iron::middleware::Chain::continue_from_handler
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/iron-0.5.1/src/middleware/mod.rs:282
  11: iron::middleware::Chain::continue_from_before
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/iron-0.5.1/src/middleware/mod.rs:276
  12: <iron::middleware::Chain as iron::middleware::Handler>::handle
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/iron-0.5.1/src/middleware/mod.rs:200
  13: <alloc::boxed::Box<dyn iron::middleware::Handler> as iron::middleware::Handler>::handle
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/iron-0.5.1/src/middleware/mod.rs:318
  14: <cratesfyi::web::CratesfyiHandler as iron::middleware::Handler>::handle::{{closure}}::{{closure}}
             at src/web/mod.rs:171
  15: <cratesfyi::web::CratesfyiHandler as iron::middleware::Handler>::handle::if_404
             at src/web/mod.rs:161
  16: <cratesfyi::web::CratesfyiHandler as iron::middleware::Handler>::handle::{{closure}}
             at src/web/mod.rs:171
  17: core::result::Result<T,E>::or_else
             at /home/joshua/.local/lib/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/result.rs:799
  18: <cratesfyi::web::CratesfyiHandler as iron::middleware::Handler>::handle
             at src/web/mod.rs:169
  19: <iron::iron::RawHandler<H> as hyper::server::Handler>::handle
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/iron-0.5.1/src/iron.rs:176
  20: hyper::server::Worker<H>::keep_alive_loop
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.10.16/src/server/mod.rs:340
  21: hyper::server::Worker<H>::handle_connection
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.10.16/src/server/mod.rs:282
  22: hyper::server::handle::{{closure}}
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.10.16/src/server/mod.rs:242
  23: hyper::server::listener::spawn_with::{{closure}}
             at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.10.16/src/server/listener.rs:50
  24: std::sys_common::backtrace::__rust_begin_short_backtrace
             at /home/joshua/.local/lib/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/sys_common/backtrace.rs:130
  25: std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}
             at /home/joshua/.local/lib/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/thread/mod.rs:475
  26: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /home/joshua/.local/lib/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:318
  27: std::panicking::try::do_call
             at /home/joshua/.local/lib/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:331
  28: __rust_try
  29: std::panicking::try
             at /home/joshua/.local/lib/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:274
  30: std::panic::catch_unwind
             at /home/joshua/.local/lib/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:394
  31: std::thread::Builder::spawn_unchecked::{{closure}}
             at /home/joshua/.local/lib/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/thread/mod.rs:474
  32: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /home/joshua/.local/lib/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:232
  33: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/49cae55760da0a43428eba73abcb659bb70cf2e4/src/liballoc/boxed.rs:1008
      <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/49cae55760da0a43428eba73abcb659bb70cf2e4/src/liballoc/boxed.rs:1008
      std::sys::unix::thread::Thread::new::thread_start
             at /rustc/49cae55760da0a43428eba73abcb659bb70cf2e4/src/libstd/sys/unix/thread.rs:87
  34: start_thread
  35: clone

Note that we already have backtrace as a transitive dependency due to failure.

Closes #817

- Don't try to serve template that doesn't exist
- Add backtrace of error in logs
@jyn514 jyn514 added E-medium Effort: This requires a fair amount of work S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed P-medium Medium priority and removed E-medium Effort: This requires a fair amount of work labels Jun 28, 2020
@jyn514
Copy link
Member Author

jyn514 commented Jun 28, 2020

r? @Kixiron

@Kixiron
Copy link
Member

Kixiron commented Jun 28, 2020

If at all possible I’d really like to get rid of the ctry! & cexpect! macros, but I think that’s out of scope for this and I’ve got an idea how to do it, so I’ll take care of it. Looks good though, that’ll help a lot with diagnosing errors

@jyn514 jyn514 merged commit a418fea into rust-lang:master Jun 28, 2020
@jyn514 jyn514 deleted the 500-handler branch June 28, 2020 02:14
return $crate::web::page::Page::new(format!("{:?}", e))
.title("An error has occured")
log::error!("{}\n{:?}", e, backtrace::Backtrace::new());
return $crate::web::page::Page::new(format!("{}", e))
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure the user should get the raw error?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see why not, usually it's something like 'File not found' which seems pretty harmless.

@Nemo157
Copy link
Member

Nemo157 commented Jun 28, 2020

If at all possible I’d really like to get rid of the ctry! & cexpect! macros, but I think that’s out of scope for this and I’ve got an idea how to do it, so I’ll take care of it.

Pretty sure we can literally just replace ctry! with ? now given that errors without an explicit status code are treated as 500s (or if we can't, could try and make it so that we can). That would allow changing cexpect! usage into .ok_or_else(|| err_msg(...))?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-medium Medium priority S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

500 internal error on error pages
3 participants