From 7153d8d6ce016ddbf47a872fac2f0bf179ae01ab Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 21 Jun 2018 20:46:45 +0400 Subject: [PATCH] Add a verbose error message for EnterError (#441) Add a verbose error message for EnterError while trying to run an executor while another executor is already running. Fixes: #410 --- tokio-current-thread/src/lib.rs | 12 ++++++++---- tokio-executor/src/enter.rs | 9 ++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tokio-current-thread/src/lib.rs b/tokio-current-thread/src/lib.rs index 81c742976..758878d59 100644 --- a/tokio-current-thread/src/lib.rs +++ b/tokio-current-thread/src/lib.rs @@ -250,14 +250,16 @@ impl CurrentThread

{ -> Result> where F: Future { - let mut enter = tokio_executor::enter().unwrap(); + let mut enter = tokio_executor::enter() + .expect("failed to start `current_thread::Runtime`"); self.enter(&mut enter).block_on(future) } /// Run the executor to completion, blocking the thread until **all** /// spawned futures have completed. pub fn run(&mut self) -> Result<(), RunError> { - let mut enter = tokio_executor::enter().unwrap(); + let mut enter = tokio_executor::enter() + .expect("failed to start `current_thread::Runtime`"); self.enter(&mut enter).run() } @@ -266,7 +268,8 @@ impl CurrentThread

{ pub fn run_timeout(&mut self, duration: Duration) -> Result<(), RunTimeoutError> { - let mut enter = tokio_executor::enter().unwrap(); + let mut enter = tokio_executor::enter() + .expect("failed to start `current_thread::Runtime`"); self.enter(&mut enter).run_timeout(duration) } @@ -276,7 +279,8 @@ impl CurrentThread

{ pub fn turn(&mut self, duration: Option) -> Result { - let mut enter = tokio_executor::enter().unwrap(); + let mut enter = tokio_executor::enter() + .expect("failed to start `current_thread::Runtime`"); self.enter(&mut enter).turn(duration) } diff --git a/tokio-executor/src/enter.rs b/tokio-executor/src/enter.rs index 39a445ad3..3da0d796b 100644 --- a/tokio-executor/src/enter.rs +++ b/tokio-executor/src/enter.rs @@ -20,11 +20,18 @@ pub struct Enter { /// An error returned by `enter` if an execution scope has already been /// entered. -#[derive(Debug)] pub struct EnterError { _a: (), } +impl fmt::Debug for EnterError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("EnterError") + .field("reason", &"attempted to run an executor while another executor is already running") + .finish() + } +} + /// Marks the current thread as being within the dynamic extent of an /// executor. ///