Context.param() panics
- Dominant language
- Rust
- Stars
- 5.1k
- Forks
- 329
- PR merge metrics
- No merged PRs in 30d
Description
## Bug Report
`Context.param()` seems to panic when used with a POST request.
#### Code/Gist
Consider the following example:
```rust
#![feature(await_macro)]
#![feature(async_await)]
#![deny(warnings)]
extern crate tide;
extern crate http;
use tide::{Context, EndpointResult, error::ResultExt};
async fn payment(cx: Context<()>) -> EndpointResult {
dbg!("Hello1");
let param: String = cx.param("extra_submit_param").client_err()?;
dbg!("Hello2");
dbg!(¶m);
dbg!("Hello3");
Ok("Hello".to_string())
}
fn main() -> Result<(), std::io::Error> {
let mut app = tide::App::new(());
app.at("/payment").post(payment);
app.serve("127.0.0.1:10000")
}
```
I attempt to post to the server using the following HTML file:
```html
Pay button
```
This is the runtime error I get:
```rust
$ RUST_BACKTRACE=1 cargo run
Compiling hello_world v0.1.0 (/home/real/projects/learn/tide/hello_world)
Finished dev [unoptimized + debuginfo] target(s) in 5.41s
Running `target/debug/hello_world`
Server is listening on: http://127.0.0.1:10000
[src/main.rs:28] "Hello1" = "Hello1"
thread 'tokio-runtime-worker-0' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:347:21
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
1: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:71
2: std::panicking::default_hook::{{closure}}
at src/libstd/sys_common/backtrace.rs:59
at src/libstd/panicking.rs:197
3: std::panicking::default_hook
at src/libstd/panicking.rs:211
4: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:474
5: std::panicking::continue_panic_fmt
at src/libstd/panicking.rs:381
6: rust_begin_unwind
at src/libstd/panicking.rs:308
7: core::panicking::panic_fmt
at src/libcore/panicking.rs:85
8: core::panicking::panic
at src/libcore/panicking.rs:49
9: core::option::Option::unwrap
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libcore/macros.rs:12
10: tide::context::Context::param
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tide-0.2.0/src/context.rs:79
11: hello_world::payment::{{closure}}
at src/main.rs:29
12: as core::future::future::Future>::poll::{{closure}}
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:39
13: std::future::set_task_context
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:74
14: as core::future::future::Future>::poll
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:39
15: std::future::poll_with_tls_context::{{closure}}
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:114
16: std::future::get_task_context
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:105
17: std::future::poll_with_tls_context
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:114
18: >::call::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tide-0.2.0/src/endpoint.rs:73
19: as core::future::future::Future>::poll::{{closure}}
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:39
20: std::future::set_task_context
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:74
21: as core::future::future::Future>::poll
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:39
22: as core::future::future::Future>::poll
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libcore/future/future.rs:117
23: as core::future::future::Future>::poll
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libcore/future/future.rs:117
24: std::future::poll_with_tls_context::{{closure}}
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:114
25: std::future::get_task_context
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:105
26: std::future::poll_with_tls_context
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:114
27: as http_service::HttpService>::respond::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tide-0.2.0/src/app.rs:275
28: as core::future::future::Future>::poll::{{closure}}
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:39
29: std::future::set_task_context
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:74
30: as core::future::future::Future>::poll
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:39
31: as core::future::future::Future>::poll
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libcore/future/future.rs:117
32: ::try_poll
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-core-preview-0.3.0-alpha.16/src/future/mod.rs:78
33: as core::future::future::Future>::poll
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-preview-0.3.0-alpha.16/src/try_future/into_future.rs:34
34: std::future::poll_with_tls_context::{{closure}}
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:114
35: std::future::get_task_context
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:105
36: std::future::poll_with_tls_context
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:114
37: as hyper::service::service::Service>::call::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/http-service-hyper-0.2.0/src/lib.rs:75
38: as core::future::future::Future>::poll::{{closure}}
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:39
39: std::future::set_task_context
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:74
40: as core::future::future::Future>::poll
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/future.rs:39
41: as core::future::future::Future>::poll
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libcore/future/future.rs:117
42: ::try_poll
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-core-preview-0.3.0-alpha.16/src/future/mod.rs:78
43: as futures::future::Future>::poll::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-preview-0.3.0-alpha.16/src/compat/compat03as01.rs:94
44: futures_util::compat::compat03as01::with_context
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-preview-0.3.0-alpha.16/src/compat/compat03as01.rs:198
45: as futures::future::Future>::poll
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-preview-0.3.0-alpha.16/src/compat/compat03as01.rs:94
46: as hyper::proto::h1::dispatch::Dispatch>::poll_msg
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.29/src/proto/h1/dispatch.rs:378
47: hyper::proto::h1::dispatch::Dispatcher::poll_write
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.29/src/proto/h1/dispatch.rs:236
48: hyper::proto::h1::dispatch::Dispatcher::poll_inner
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.29/src/proto/h1/dispatch.rs:101
49: hyper::proto::h1::dispatch::Dispatcher::poll_catch
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.29/src/proto/h1/dispatch.rs:86
50: as futures::future::Future>::poll
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.29/src/proto/h1/dispatch.rs:347
51: as futures::future::Future>::poll
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.27/src/future/either.rs:35
52: futures::future::option::>::poll
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.27/src/future/option.rs:12
53: as futures::future::Future>::poll
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.29/src/server/conn.rs:946
54: as futures::future::Future>::poll
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.12.29/src/server/conn.rs:886
55: as futures::future::Future>::poll
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.27/src/future/mod.rs:113
56: futures::task_impl::Spawn::poll_future_notify::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.27/src/task_impl/mod.rs:329
57: futures::task_impl::Spawn::enter::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.27/src/task_impl/mod.rs:399
58: futures::task_impl::std::set
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.27/src/task_impl/std/mod.rs:83
59: futures::task_impl::Spawn::enter
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.27/src/task_impl/mod.rs:399
60: futures::task_impl::Spawn::poll_fn_notify
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.27/src/task_impl/mod.rs:291
61: futures::task_impl::Spawn::poll_future_notify
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.27/src/task_impl/mod.rs:329
62: tokio_threadpool::task::Task::run::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.14/src/task/mod.rs:145
63: core::ops::function::FnOnce::call_once
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libcore/ops/function.rs:231
64: as core::ops::function::FnOnce<()>>::call_once
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/panic.rs:309
65: std::panicking::try::do_call
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/panicking.rs:293
66: __rust_maybe_catch_panic
at src/libpanic_unwind/lib.rs:85
67: std::panicking::try
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/panicking.rs:272
68: std::panic::catch_unwind
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/panic.rs:388
69: tokio_threadpool::task::Task::run
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.14/src/task/mod.rs:130
70: tokio_threadpool::worker::Worker::run_task2
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.14/src/worker/mod.rs:567
71: tokio_threadpool::worker::Worker::run_task
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.14/src/worker/mod.rs:459
72: tokio_threadpool::worker::Worker::try_run_owned_task
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.14/src/worker/mod.rs:390
73: tokio_threadpool::worker::Worker::try_run_task
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.14/src/worker/mod.rs:297
74: tokio_threadpool::worker::Worker::run
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.14/src/worker/mod.rs:241
75: tokio::runtime::threadpool::builder::Builder::build::{{closure}}::{{closure}}::{{closure}}::{{closure}}::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.21/src/runtime/threadpool/builder.rs:381
76: tokio_trace_core::dispatcher::with_default
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-trace-core-0.2.0/src/dispatcher.rs:64
77: tokio::runtime::threadpool::builder::Builder::build::{{closure}}::{{closure}}::{{closure}}::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.21/src/runtime/threadpool/builder.rs:380
78: tokio_timer::timer::handle::with_default::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.11/src/timer/handle.rs:101
79: std::thread::local::LocalKey::try_with
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/thread/local.rs:299
80: std::thread::local::LocalKey::with
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/thread/local.rs:245
81: tokio_timer::timer::handle::with_default
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.11/src/timer/handle.rs:84
82: tokio::runtime::threadpool::builder::Builder::build::{{closure}}::{{closure}}::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.21/src/runtime/threadpool/builder.rs:379
83: tokio_timer::clock::clock::with_default::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.11/src/clock/clock.rs:137
84: std::thread::local::LocalKey::try_with
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/thread/local.rs:299
85: std::thread::local::LocalKey::with
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/thread/local.rs:245
86: tokio_timer::clock::clock::with_default
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-timer-0.2.11/src/clock/clock.rs:117
87: tokio::runtime::threadpool::builder::Builder::build::{{closure}}::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.21/src/runtime/threadpool/builder.rs:378
88: tokio_reactor::with_default::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-reactor-0.1.9/src/lib.rs:237
89: std::thread::local::LocalKey::try_with
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/thread/local.rs:299
90: std::thread::local::LocalKey::with
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/thread/local.rs:245
91: tokio_reactor::with_default
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-reactor-0.1.9/src/lib.rs:217
92: tokio::runtime::threadpool::builder::Builder::build::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.21/src/runtime/threadpool/builder.rs:377
93: tokio_threadpool::callback::Callback::call
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.14/src/callback.rs:22
94: tokio_threadpool::worker::Worker::do_run::{{closure}}::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.14/src/worker/mod.rs:127
95: tokio_executor::global::with_default::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-executor-0.1.7/src/global.rs:209
96: std::thread::local::LocalKey::try_with
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/thread/local.rs:299
97: std::thread::local::LocalKey::with
at /rustc/d595b113584f8f446957469951fd5d31adc2a44e/src/libstd/thread/local.rs:245
98: tokio_executor::global::with_default
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-executor-0.1.7/src/global.rs:178
99: tokio_threadpool::worker::Worker::do_run::{{closure}}
at /home/real/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.14/src/worker/mod.rs:125
```
#### Expected behavior/code
I expect the server to never crash, and also to print the value of `extra_submit_param`.
#### Environment
- Rust toolchain version(s):
```bash
$ rustc --version
rustc 1.36.0-nightly (d595b1135 2019-05-10)
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS
Release: 16.04
Codename: xenial
```
#### Possible Solution
I couldn't use the stack trace to figure out where would the problem be.
Contributor guide
Assessment
This issue has not been assessed yet.