Skip to content

Commit

Permalink
chore: Rename Error to BoxError (#2011)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored Oct 17, 2024
1 parent 58345a6 commit 758d4f9
Show file tree
Hide file tree
Showing 25 changed files with 114 additions and 111 deletions.
2 changes: 1 addition & 1 deletion tonic/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub type BoxBody = http_body_util::combinators::UnsyncBoxBody<bytes::Bytes, crat
pub fn boxed<B>(body: B) -> BoxBody
where
B: http_body::Body<Data = bytes::Bytes> + Send + 'static,
B::Error: Into<crate::Error>,
B::Error: Into<crate::BoxError>,
{
body.map_err(crate::Status::map_error).boxed_unsync()
}
Expand Down
10 changes: 5 additions & 5 deletions tonic/src/client/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<T> Grpc<T> {
where
T: GrpcService<BoxBody>,
T::ResponseBody: Body + Send + 'static,
<T::ResponseBody as Body>::Error: Into<crate::Error>,
<T::ResponseBody as Body>::Error: Into<crate::BoxError>,
C: Codec<Encode = M1, Decode = M2>,
M1: Send + Sync + 'static,
M2: Send + Sync + 'static,
Expand All @@ -232,7 +232,7 @@ impl<T> Grpc<T> {
where
T: GrpcService<BoxBody>,
T::ResponseBody: Body + Send + 'static,
<T::ResponseBody as Body>::Error: Into<crate::Error>,
<T::ResponseBody as Body>::Error: Into<crate::BoxError>,
S: Stream<Item = M1> + Send + 'static,
C: Codec<Encode = M1, Decode = M2>,
M1: Send + Sync + 'static,
Expand Down Expand Up @@ -269,7 +269,7 @@ impl<T> Grpc<T> {
where
T: GrpcService<BoxBody>,
T::ResponseBody: Body + Send + 'static,
<T::ResponseBody as Body>::Error: Into<crate::Error>,
<T::ResponseBody as Body>::Error: Into<crate::BoxError>,
C: Codec<Encode = M1, Decode = M2>,
M1: Send + Sync + 'static,
M2: Send + Sync + 'static,
Expand All @@ -288,7 +288,7 @@ impl<T> Grpc<T> {
where
T: GrpcService<BoxBody>,
T::ResponseBody: Body + Send + 'static,
<T::ResponseBody as Body>::Error: Into<crate::Error>,
<T::ResponseBody as Body>::Error: Into<crate::BoxError>,
S: Stream<Item = M1> + Send + 'static,
C: Codec<Encode = M1, Decode = M2>,
M1: Send + Sync + 'static,
Expand Down Expand Up @@ -328,7 +328,7 @@ impl<T> Grpc<T> {
where
T: GrpcService<BoxBody>,
T::ResponseBody: Body + Send + 'static,
<T::ResponseBody as Body>::Error: Into<crate::Error>,
<T::ResponseBody as Body>::Error: Into<crate::BoxError>,
{
let encoding = CompressionEncoding::from_encoding_header(
response.headers(),
Expand Down
6 changes: 3 additions & 3 deletions tonic/src/client/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub trait GrpcService<ReqBody> {
/// Responses body given by the service.
type ResponseBody: Body;
/// Errors produced by the service.
type Error: Into<crate::Error>;
type Error: Into<crate::BoxError>;
/// The future response value.
type Future: Future<Output = Result<http::Response<Self::ResponseBody>, Self::Error>>;

Expand All @@ -32,9 +32,9 @@ pub trait GrpcService<ReqBody> {
impl<T, ReqBody, ResBody> GrpcService<ReqBody> for T
where
T: Service<http::Request<ReqBody>, Response = http::Response<ResBody>>,
T::Error: Into<crate::Error>,
T::Error: Into<crate::BoxError>,
ResBody: Body,
<ResBody as Body>::Error: Into<crate::Error>,
<ResBody as Body>::Error: Into<crate::BoxError>,
{
type ResponseBody = ResBody;
type Error = T::Error;
Expand Down
8 changes: 4 additions & 4 deletions tonic/src/codec/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<T> Streaming<T> {
) -> Self
where
B: Body + Send + 'static,
B::Error: Into<crate::Error>,
B::Error: Into<crate::BoxError>,
D: Decoder<Item = T, Error = Status> + Send + 'static,
{
Self::new(
Expand All @@ -81,7 +81,7 @@ impl<T> Streaming<T> {
pub fn new_empty<B, D>(decoder: D, body: B) -> Self
where
B: Body + Send + 'static,
B::Error: Into<crate::Error>,
B::Error: Into<crate::BoxError>,
D: Decoder<Item = T, Error = Status> + Send + 'static,
{
Self::new(decoder, body, Direction::EmptyResponse, None, None)
Expand All @@ -97,7 +97,7 @@ impl<T> Streaming<T> {
) -> Self
where
B: Body + Send + 'static,
B::Error: Into<crate::Error>,
B::Error: Into<crate::BoxError>,
D: Decoder<Item = T, Error = Status> + Send + 'static,
{
Self::new(
Expand All @@ -118,7 +118,7 @@ impl<T> Streaming<T> {
) -> Self
where
B: Body + Send + 'static,
B::Error: Into<crate::Error>,
B::Error: Into<crate::BoxError>,
D: Decoder<Item = T, Error = Status> + Send + 'static,
{
let buffer_size = decoder.buffer_settings().buffer_size;
Expand Down
2 changes: 1 addition & 1 deletion tonic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub use request::{IntoRequest, IntoStreamingRequest, Request};
pub use response::Response;
pub use status::{Code, ConnectError, Status, TimeoutExpired};

pub(crate) type Error = Box<dyn std::error::Error + Send + Sync>;
pub(crate) type BoxError = Box<dyn std::error::Error + Send + Sync>;

#[doc(hidden)]
#[cfg(feature = "codegen")]
Expand Down
12 changes: 6 additions & 6 deletions tonic/src/server/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ where
where
S: UnaryService<T::Decode, Response = T::Encode>,
B: Body + Send + 'static,
B::Error: Into<crate::Error> + Send,
B::Error: Into<crate::BoxError> + Send,
{
let accept_encoding = CompressionEncoding::from_accept_encoding_header(
req.headers(),
Expand Down Expand Up @@ -272,7 +272,7 @@ where
S: ServerStreamingService<T::Decode, Response = T::Encode>,
S::ResponseStream: Send + 'static,
B: Body + Send + 'static,
B::Error: Into<crate::Error> + Send,
B::Error: Into<crate::BoxError> + Send,
{
let accept_encoding = CompressionEncoding::from_accept_encoding_header(
req.headers(),
Expand Down Expand Up @@ -312,7 +312,7 @@ where
where
S: ClientStreamingService<T::Decode, Response = T::Encode>,
B: Body + Send + 'static,
B::Error: Into<crate::Error> + Send + 'static,
B::Error: Into<crate::BoxError> + Send + 'static,
{
let accept_encoding = CompressionEncoding::from_accept_encoding_header(
req.headers(),
Expand Down Expand Up @@ -346,7 +346,7 @@ where
S: StreamingService<T::Decode, Response = T::Encode> + Send,
S::ResponseStream: Send + 'static,
B: Body + Send + 'static,
B::Error: Into<crate::Error> + Send,
B::Error: Into<crate::BoxError> + Send,
{
let accept_encoding = CompressionEncoding::from_accept_encoding_header(
req.headers(),
Expand All @@ -371,7 +371,7 @@ where
) -> Result<Request<T::Decode>, Status>
where
B: Body + Send + 'static,
B::Error: Into<crate::Error> + Send,
B::Error: Into<crate::BoxError> + Send,
{
let request_compression_encoding = self.request_encoding_if_supported(&request)?;

Expand Down Expand Up @@ -404,7 +404,7 @@ where
) -> Result<Request<Streaming<T::Decode>>, Status>
where
B: Body + Send + 'static,
B::Error: Into<crate::Error> + Send,
B::Error: Into<crate::BoxError> + Send,
{
let encoding = self.request_encoding_if_supported(&request)?;

Expand Down
6 changes: 3 additions & 3 deletions tonic/src/service/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ async fn unimplemented() -> impl axum::response::IntoResponse {
impl<B> Service<Request<B>> for Routes
where
B: http_body::Body<Data = bytes::Bytes> + Send + 'static,
B::Error: Into<crate::Error>,
B::Error: Into<crate::BoxError>,
{
type Response = Response<BoxBody>;
type Error = crate::Error;
type Error = crate::BoxError;
type Future = RoutesFuture;

#[inline]
Expand All @@ -168,7 +168,7 @@ impl fmt::Debug for RoutesFuture {
}

impl Future for RoutesFuture {
type Output = Result<Response<BoxBody>, crate::Error>;
type Output = Result<Response<BoxBody>, crate::BoxError>;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match ready!(Pin::new(&mut self.as_mut().0).poll(cx)) {
Expand Down
6 changes: 3 additions & 3 deletions tonic/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,10 +883,10 @@ impl From<Code> for i32 {
#[cfg(test)]
mod tests {
use super::*;
use crate::Error;
use crate::BoxError;

#[derive(Debug)]
struct Nested(Error);
struct Nested(BoxError);

impl fmt::Display for Nested {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand All @@ -911,7 +911,7 @@ mod tests {

#[test]
fn from_error_unknown() {
let orig: Error = "peek-a-boo".into();
let orig: BoxError = "peek-a-boo".into();
let found = Status::from_error(orig);

assert_eq!(found.code(), Code::Unknown);
Expand Down
6 changes: 3 additions & 3 deletions tonic/src/transport/channel/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Endpoint {
pub fn new<D>(dst: D) -> Result<Self, Error>
where
D: TryInto<Self>,
D::Error: Into<crate::Error>,
D::Error: Into<crate::BoxError>,
{
let me = dst.try_into().map_err(|e| Error::from_source(e.into()))?;
#[cfg(feature = "tls")]
Expand Down Expand Up @@ -366,7 +366,7 @@ impl Endpoint {
C: Service<Uri> + Send + 'static,
C::Response: rt::Read + rt::Write + Send + Unpin,
C::Future: Send,
crate::Error: From<C::Error> + Send,
crate::BoxError: From<C::Error> + Send,
{
let connector = self.connector(connector);

Expand All @@ -391,7 +391,7 @@ impl Endpoint {
C: Service<Uri> + Send + 'static,
C::Response: rt::Read + rt::Write + Send + Unpin,
C::Future: Send,
crate::Error: From<C::Error> + Send,
crate::BoxError: From<C::Error> + Send,
{
let connector = self.connector(connector);
if let Some(connect_timeout) = self.connect_timeout {
Expand Down
10 changes: 5 additions & 5 deletions tonic/src/transport/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ const DEFAULT_BUFFER_SIZE: usize = 1024;
/// cloning the `Channel` type is cheap and encouraged.
#[derive(Clone)]
pub struct Channel {
svc: Buffer<Request<BoxBody>, BoxFuture<'static, Result<Response<BoxBody>, crate::Error>>>,
svc: Buffer<Request<BoxBody>, BoxFuture<'static, Result<Response<BoxBody>, crate::BoxError>>>,
}

/// A future that resolves to an HTTP response.
///
/// This is returned by the `Service::call` on [`Channel`].
pub struct ResponseFuture {
inner: BufferResponseFuture<BoxFuture<'static, Result<Response<BoxBody>, crate::Error>>>,
inner: BufferResponseFuture<BoxFuture<'static, Result<Response<BoxBody>, crate::BoxError>>>,
}

impl Channel {
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Channel {
pub(crate) fn new<C>(connector: C, endpoint: Endpoint) -> Self
where
C: Service<Uri> + Send + 'static,
C::Error: Into<crate::Error> + Send,
C::Error: Into<crate::BoxError> + Send,
C::Future: Send,
C::Response: rt::Read + rt::Write + HyperConnection + Unpin + Send + 'static,
{
Expand All @@ -165,7 +165,7 @@ impl Channel {
pub(crate) async fn connect<C>(connector: C, endpoint: Endpoint) -> Result<Self, super::Error>
where
C: Service<Uri> + Send + 'static,
C::Error: Into<crate::Error> + Send,
C::Error: Into<crate::BoxError> + Send,
C::Future: Unpin + Send,
C::Response: rt::Read + rt::Write + HyperConnection + Unpin + Send + 'static,
{
Expand All @@ -184,7 +184,7 @@ impl Channel {
pub(crate) fn balance<D, E>(discover: D, buffer_size: usize, executor: E) -> Self
where
D: Discover<Service = Connection> + Unpin + Send + 'static,
D::Error: Into<crate::Error>,
D::Error: Into<crate::BoxError>,
D::Key: Hash + Send + Clone,
E: Executor<BoxFuture<'static, ()>> + Send + Sync + 'static,
{
Expand Down
4 changes: 2 additions & 2 deletions tonic/src/transport/channel/service/add_origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ impl<T, ReqBody> Service<Request<ReqBody>> for AddOrigin<T>
where
T: Service<Request<ReqBody>>,
T::Future: Send + 'static,
T::Error: Into<crate::Error>,
T::Error: Into<crate::BoxError>,
{
type Response = T::Response;
type Error = crate::Error;
type Error = crate::BoxError;
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Expand Down
21 changes: 12 additions & 9 deletions tonic/src/transport/channel/service/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ use tower::{
use tower_service::Service;

pub(crate) struct Connection {
inner: BoxService<Request<BoxBody>, Response<BoxBody>, crate::Error>,
inner: BoxService<Request<BoxBody>, Response<BoxBody>, crate::BoxError>,
}

impl Connection {
fn new<C>(connector: C, endpoint: Endpoint, is_lazy: bool) -> Self
where
C: Service<Uri> + Send + 'static,
C::Error: Into<crate::Error> + Send,
C::Error: Into<crate::BoxError> + Send,
C::Future: Send,
C::Response: rt::Read + rt::Write + Unpin + Send + 'static,
{
Expand Down Expand Up @@ -77,10 +77,13 @@ impl Connection {
}
}

pub(crate) async fn connect<C>(connector: C, endpoint: Endpoint) -> Result<Self, crate::Error>
pub(crate) async fn connect<C>(
connector: C,
endpoint: Endpoint,
) -> Result<Self, crate::BoxError>
where
C: Service<Uri> + Send + 'static,
C::Error: Into<crate::Error> + Send,
C::Error: Into<crate::BoxError> + Send,
C::Future: Unpin + Send,
C::Response: rt::Read + rt::Write + Unpin + Send + 'static,
{
Expand All @@ -90,7 +93,7 @@ impl Connection {
pub(crate) fn lazy<C>(connector: C, endpoint: Endpoint) -> Self
where
C: Service<Uri> + Send + 'static,
C::Error: Into<crate::Error> + Send,
C::Error: Into<crate::BoxError> + Send,
C::Future: Send,
C::Response: rt::Read + rt::Write + Unpin + Send + 'static,
{
Expand All @@ -100,7 +103,7 @@ impl Connection {

impl Service<Request<BoxBody>> for Connection {
type Response = Response<BoxBody>;
type Error = crate::Error;
type Error = crate::BoxError;
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Expand Down Expand Up @@ -138,7 +141,7 @@ impl From<hyper::client::conn::http2::SendRequest<BoxBody>> for SendRequest {

impl tower::Service<Request<BoxBody>> for SendRequest {
type Response = Response<BoxBody>;
type Error = crate::Error;
type Error = crate::BoxError;
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Expand Down Expand Up @@ -171,12 +174,12 @@ impl<C> MakeSendRequestService<C> {
impl<C> tower::Service<Uri> for MakeSendRequestService<C>
where
C: Service<Uri> + Send + 'static,
C::Error: Into<crate::Error> + Send,
C::Error: Into<crate::BoxError> + Send,
C::Future: Send,
C::Response: rt::Read + rt::Write + Unpin + Send,
{
type Response = SendRequest;
type Error = crate::Error;
type Error = crate::BoxError;
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Expand Down
4 changes: 2 additions & 2 deletions tonic/src/transport/channel/service/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where
C: Service<Uri>,
C::Response: rt::Read + rt::Write + Unpin + Send + 'static,
C::Future: Send + 'static,
crate::Error: From<C::Error> + Send + 'static,
crate::BoxError: From<C::Error> + Send + 'static,
{
type Response = BoxedIo;
type Error = ConnectError;
Expand Down Expand Up @@ -69,7 +69,7 @@ where
};
}

Ok::<_, crate::Error>(BoxedIo::new(io))
Ok::<_, crate::BoxError>(BoxedIo::new(io))
}
.await
.map_err(ConnectError)
Expand Down
Loading

0 comments on commit 758d4f9

Please sign in to comment.