Skip to content

Commit

Permalink
Improve error message when using blocking Client inside a Future
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jul 19, 2019
1 parent 9a9bcac commit afbd9e6
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ impl Error {
Kind::Io(ref e) => Some(e),
Kind::UrlEncoded(ref e) => Some(e),
Kind::Json(ref e) => Some(e),
Kind::Executor(ref e) => Some(e),
Kind::UrlBadScheme |
Kind::TooManyRedirects |
Kind::RedirectLoop |
Kind::Status(_) |
Kind::UnknownProxyScheme |
Kind::Timer => None,
Kind::Timer |
Kind::BlockingClientInFutureContext => None,
}
}

Expand Down Expand Up @@ -248,6 +248,8 @@ impl fmt::Debug for Error {
}
}

static BLOCK_IN_FUTURE: &'static str = "blocking Client used inside a Future context";

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(ref url) = self.inner.url {
Expand Down Expand Up @@ -287,7 +289,7 @@ impl fmt::Display for Error {
}
Kind::UnknownProxyScheme => f.write_str("Unknown proxy scheme"),
Kind::Timer => f.write_str("timer unavailable"),
Kind::Executor(ref e) => fmt::Display::fmt(e, f),
Kind::BlockingClientInFutureContext => f.write_str(BLOCK_IN_FUTURE),
}
}
}
Expand Down Expand Up @@ -324,7 +326,7 @@ impl StdError for Error {
}
Kind::UnknownProxyScheme => "Unknown proxy scheme",
Kind::Timer => "timer unavailable",
Kind::Executor(ref e) => e.description(),
Kind::BlockingClientInFutureContext => BLOCK_IN_FUTURE,
}
}

Expand All @@ -347,13 +349,13 @@ impl StdError for Error {
Kind::Io(ref e) => e.cause(),
Kind::UrlEncoded(ref e) => e.cause(),
Kind::Json(ref e) => e.cause(),
Kind::Executor(ref e) => e.cause(),
Kind::UrlBadScheme |
Kind::TooManyRedirects |
Kind::RedirectLoop |
Kind::Status(_) |
Kind::UnknownProxyScheme |
Kind::Timer => None,
Kind::Timer |
Kind::BlockingClientInFutureContext => None,
}
}

Expand All @@ -374,13 +376,13 @@ impl StdError for Error {
Kind::Io(ref e) => e.source(),
Kind::UrlEncoded(ref e) => e.source(),
Kind::Json(ref e) => e.source(),
Kind::Executor(ref e) => e.source(),
Kind::UrlBadScheme |
Kind::TooManyRedirects |
Kind::RedirectLoop |
Kind::Status(_) |
Kind::UnknownProxyScheme |
Kind::Timer => None,
Kind::Timer |
Kind::BlockingClientInFutureContext => None,
}
}
}
Expand Down Expand Up @@ -408,7 +410,7 @@ pub(crate) enum Kind {
Status(StatusCode),
UnknownProxyScheme,
Timer,
Executor(EnterError),
BlockingClientInFutureContext,
}


Expand Down Expand Up @@ -487,8 +489,8 @@ where T: Into<Kind> {
}

impl From<EnterError> for Kind {
fn from(err: EnterError) -> Kind {
Kind::Executor(err)
fn from(_err: EnterError) -> Kind {
Kind::BlockingClientInFutureContext
}
}

Expand Down

1 comment on commit afbd9e6

@stammaja
Copy link

@stammaja stammaja commented on afbd9e6 Aug 13, 2019

Choose a reason for hiding this comment

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

Hi @seanmonstar , Why is this forbidden in the new version?

I tried to update an APP which uses Actix web server and in handlers calls other API's using Reqwest when I got this error.

Please sign in to comment.