Skip to content

Commit 758d4f9

Browse files
authored
chore: Rename Error to BoxError (#2011)
1 parent 58345a6 commit 758d4f9

File tree

25 files changed

+114
-111
lines changed

25 files changed

+114
-111
lines changed

tonic/src/body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub type BoxBody = http_body_util::combinators::UnsyncBoxBody<bytes::Bytes, crat
99
pub fn boxed<B>(body: B) -> BoxBody
1010
where
1111
B: http_body::Body<Data = bytes::Bytes> + Send + 'static,
12-
B::Error: Into<crate::Error>,
12+
B::Error: Into<crate::BoxError>,
1313
{
1414
body.map_err(crate::Status::map_error).boxed_unsync()
1515
}

tonic/src/client/grpc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl<T> Grpc<T> {
213213
where
214214
T: GrpcService<BoxBody>,
215215
T::ResponseBody: Body + Send + 'static,
216-
<T::ResponseBody as Body>::Error: Into<crate::Error>,
216+
<T::ResponseBody as Body>::Error: Into<crate::BoxError>,
217217
C: Codec<Encode = M1, Decode = M2>,
218218
M1: Send + Sync + 'static,
219219
M2: Send + Sync + 'static,
@@ -232,7 +232,7 @@ impl<T> Grpc<T> {
232232
where
233233
T: GrpcService<BoxBody>,
234234
T::ResponseBody: Body + Send + 'static,
235-
<T::ResponseBody as Body>::Error: Into<crate::Error>,
235+
<T::ResponseBody as Body>::Error: Into<crate::BoxError>,
236236
S: Stream<Item = M1> + Send + 'static,
237237
C: Codec<Encode = M1, Decode = M2>,
238238
M1: Send + Sync + 'static,
@@ -269,7 +269,7 @@ impl<T> Grpc<T> {
269269
where
270270
T: GrpcService<BoxBody>,
271271
T::ResponseBody: Body + Send + 'static,
272-
<T::ResponseBody as Body>::Error: Into<crate::Error>,
272+
<T::ResponseBody as Body>::Error: Into<crate::BoxError>,
273273
C: Codec<Encode = M1, Decode = M2>,
274274
M1: Send + Sync + 'static,
275275
M2: Send + Sync + 'static,
@@ -288,7 +288,7 @@ impl<T> Grpc<T> {
288288
where
289289
T: GrpcService<BoxBody>,
290290
T::ResponseBody: Body + Send + 'static,
291-
<T::ResponseBody as Body>::Error: Into<crate::Error>,
291+
<T::ResponseBody as Body>::Error: Into<crate::BoxError>,
292292
S: Stream<Item = M1> + Send + 'static,
293293
C: Codec<Encode = M1, Decode = M2>,
294294
M1: Send + Sync + 'static,
@@ -328,7 +328,7 @@ impl<T> Grpc<T> {
328328
where
329329
T: GrpcService<BoxBody>,
330330
T::ResponseBody: Body + Send + 'static,
331-
<T::ResponseBody as Body>::Error: Into<crate::Error>,
331+
<T::ResponseBody as Body>::Error: Into<crate::BoxError>,
332332
{
333333
let encoding = CompressionEncoding::from_encoding_header(
334334
response.headers(),

tonic/src/client/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub trait GrpcService<ReqBody> {
1414
/// Responses body given by the service.
1515
type ResponseBody: Body;
1616
/// Errors produced by the service.
17-
type Error: Into<crate::Error>;
17+
type Error: Into<crate::BoxError>;
1818
/// The future response value.
1919
type Future: Future<Output = Result<http::Response<Self::ResponseBody>, Self::Error>>;
2020

@@ -32,9 +32,9 @@ pub trait GrpcService<ReqBody> {
3232
impl<T, ReqBody, ResBody> GrpcService<ReqBody> for T
3333
where
3434
T: Service<http::Request<ReqBody>, Response = http::Response<ResBody>>,
35-
T::Error: Into<crate::Error>,
35+
T::Error: Into<crate::BoxError>,
3636
ResBody: Body,
37-
<ResBody as Body>::Error: Into<crate::Error>,
37+
<ResBody as Body>::Error: Into<crate::BoxError>,
3838
{
3939
type ResponseBody = ResBody;
4040
type Error = T::Error;

tonic/src/codec/decode.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<T> Streaming<T> {
6565
) -> Self
6666
where
6767
B: Body + Send + 'static,
68-
B::Error: Into<crate::Error>,
68+
B::Error: Into<crate::BoxError>,
6969
D: Decoder<Item = T, Error = Status> + Send + 'static,
7070
{
7171
Self::new(
@@ -81,7 +81,7 @@ impl<T> Streaming<T> {
8181
pub fn new_empty<B, D>(decoder: D, body: B) -> Self
8282
where
8383
B: Body + Send + 'static,
84-
B::Error: Into<crate::Error>,
84+
B::Error: Into<crate::BoxError>,
8585
D: Decoder<Item = T, Error = Status> + Send + 'static,
8686
{
8787
Self::new(decoder, body, Direction::EmptyResponse, None, None)
@@ -97,7 +97,7 @@ impl<T> Streaming<T> {
9797
) -> Self
9898
where
9999
B: Body + Send + 'static,
100-
B::Error: Into<crate::Error>,
100+
B::Error: Into<crate::BoxError>,
101101
D: Decoder<Item = T, Error = Status> + Send + 'static,
102102
{
103103
Self::new(
@@ -118,7 +118,7 @@ impl<T> Streaming<T> {
118118
) -> Self
119119
where
120120
B: Body + Send + 'static,
121-
B::Error: Into<crate::Error>,
121+
B::Error: Into<crate::BoxError>,
122122
D: Decoder<Item = T, Error = Status> + Send + 'static,
123123
{
124124
let buffer_size = decoder.buffer_settings().buffer_size;

tonic/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub use request::{IntoRequest, IntoStreamingRequest, Request};
128128
pub use response::Response;
129129
pub use status::{Code, ConnectError, Status, TimeoutExpired};
130130

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

133133
#[doc(hidden)]
134134
#[cfg(feature = "codegen")]

tonic/src/server/grpc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ where
228228
where
229229
S: UnaryService<T::Decode, Response = T::Encode>,
230230
B: Body + Send + 'static,
231-
B::Error: Into<crate::Error> + Send,
231+
B::Error: Into<crate::BoxError> + Send,
232232
{
233233
let accept_encoding = CompressionEncoding::from_accept_encoding_header(
234234
req.headers(),
@@ -272,7 +272,7 @@ where
272272
S: ServerStreamingService<T::Decode, Response = T::Encode>,
273273
S::ResponseStream: Send + 'static,
274274
B: Body + Send + 'static,
275-
B::Error: Into<crate::Error> + Send,
275+
B::Error: Into<crate::BoxError> + Send,
276276
{
277277
let accept_encoding = CompressionEncoding::from_accept_encoding_header(
278278
req.headers(),
@@ -312,7 +312,7 @@ where
312312
where
313313
S: ClientStreamingService<T::Decode, Response = T::Encode>,
314314
B: Body + Send + 'static,
315-
B::Error: Into<crate::Error> + Send + 'static,
315+
B::Error: Into<crate::BoxError> + Send + 'static,
316316
{
317317
let accept_encoding = CompressionEncoding::from_accept_encoding_header(
318318
req.headers(),
@@ -346,7 +346,7 @@ where
346346
S: StreamingService<T::Decode, Response = T::Encode> + Send,
347347
S::ResponseStream: Send + 'static,
348348
B: Body + Send + 'static,
349-
B::Error: Into<crate::Error> + Send,
349+
B::Error: Into<crate::BoxError> + Send,
350350
{
351351
let accept_encoding = CompressionEncoding::from_accept_encoding_header(
352352
req.headers(),
@@ -371,7 +371,7 @@ where
371371
) -> Result<Request<T::Decode>, Status>
372372
where
373373
B: Body + Send + 'static,
374-
B::Error: Into<crate::Error> + Send,
374+
B::Error: Into<crate::BoxError> + Send,
375375
{
376376
let request_compression_encoding = self.request_encoding_if_supported(&request)?;
377377

@@ -404,7 +404,7 @@ where
404404
) -> Result<Request<Streaming<T::Decode>>, Status>
405405
where
406406
B: Body + Send + 'static,
407-
B::Error: Into<crate::Error> + Send,
407+
B::Error: Into<crate::BoxError> + Send,
408408
{
409409
let encoding = self.request_encoding_if_supported(&request)?;
410410

tonic/src/service/router.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ async fn unimplemented() -> impl axum::response::IntoResponse {
143143
impl<B> Service<Request<B>> for Routes
144144
where
145145
B: http_body::Body<Data = bytes::Bytes> + Send + 'static,
146-
B::Error: Into<crate::Error>,
146+
B::Error: Into<crate::BoxError>,
147147
{
148148
type Response = Response<BoxBody>;
149-
type Error = crate::Error;
149+
type Error = crate::BoxError;
150150
type Future = RoutesFuture;
151151

152152
#[inline]
@@ -168,7 +168,7 @@ impl fmt::Debug for RoutesFuture {
168168
}
169169

170170
impl Future for RoutesFuture {
171-
type Output = Result<Response<BoxBody>, crate::Error>;
171+
type Output = Result<Response<BoxBody>, crate::BoxError>;
172172

173173
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
174174
match ready!(Pin::new(&mut self.as_mut().0).poll(cx)) {

tonic/src/status.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,10 +883,10 @@ impl From<Code> for i32 {
883883
#[cfg(test)]
884884
mod tests {
885885
use super::*;
886-
use crate::Error;
886+
use crate::BoxError;
887887

888888
#[derive(Debug)]
889-
struct Nested(Error);
889+
struct Nested(BoxError);
890890

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

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

917917
assert_eq!(found.code(), Code::Unknown);

tonic/src/transport/channel/endpoint.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Endpoint {
4646
pub fn new<D>(dst: D) -> Result<Self, Error>
4747
where
4848
D: TryInto<Self>,
49-
D::Error: Into<crate::Error>,
49+
D::Error: Into<crate::BoxError>,
5050
{
5151
let me = dst.try_into().map_err(|e| Error::from_source(e.into()))?;
5252
#[cfg(feature = "tls")]
@@ -366,7 +366,7 @@ impl Endpoint {
366366
C: Service<Uri> + Send + 'static,
367367
C::Response: rt::Read + rt::Write + Send + Unpin,
368368
C::Future: Send,
369-
crate::Error: From<C::Error> + Send,
369+
crate::BoxError: From<C::Error> + Send,
370370
{
371371
let connector = self.connector(connector);
372372

@@ -391,7 +391,7 @@ impl Endpoint {
391391
C: Service<Uri> + Send + 'static,
392392
C::Response: rt::Read + rt::Write + Send + Unpin,
393393
C::Future: Send,
394-
crate::Error: From<C::Error> + Send,
394+
crate::BoxError: From<C::Error> + Send,
395395
{
396396
let connector = self.connector(connector);
397397
if let Some(connect_timeout) = self.connect_timeout {

tonic/src/transport/channel/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ const DEFAULT_BUFFER_SIZE: usize = 1024;
6464
/// cloning the `Channel` type is cheap and encouraged.
6565
#[derive(Clone)]
6666
pub struct Channel {
67-
svc: Buffer<Request<BoxBody>, BoxFuture<'static, Result<Response<BoxBody>, crate::Error>>>,
67+
svc: Buffer<Request<BoxBody>, BoxFuture<'static, Result<Response<BoxBody>, crate::BoxError>>>,
6868
}
6969

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

7777
impl Channel {
@@ -147,7 +147,7 @@ impl Channel {
147147
pub(crate) fn new<C>(connector: C, endpoint: Endpoint) -> Self
148148
where
149149
C: Service<Uri> + Send + 'static,
150-
C::Error: Into<crate::Error> + Send,
150+
C::Error: Into<crate::BoxError> + Send,
151151
C::Future: Send,
152152
C::Response: rt::Read + rt::Write + HyperConnection + Unpin + Send + 'static,
153153
{
@@ -165,7 +165,7 @@ impl Channel {
165165
pub(crate) async fn connect<C>(connector: C, endpoint: Endpoint) -> Result<Self, super::Error>
166166
where
167167
C: Service<Uri> + Send + 'static,
168-
C::Error: Into<crate::Error> + Send,
168+
C::Error: Into<crate::BoxError> + Send,
169169
C::Future: Unpin + Send,
170170
C::Response: rt::Read + rt::Write + HyperConnection + Unpin + Send + 'static,
171171
{
@@ -184,7 +184,7 @@ impl Channel {
184184
pub(crate) fn balance<D, E>(discover: D, buffer_size: usize, executor: E) -> Self
185185
where
186186
D: Discover<Service = Connection> + Unpin + Send + 'static,
187-
D::Error: Into<crate::Error>,
187+
D::Error: Into<crate::BoxError>,
188188
D::Key: Hash + Send + Clone,
189189
E: Executor<BoxFuture<'static, ()>> + Send + Sync + 'static,
190190
{

tonic/src/transport/channel/service/add_origin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ impl<T, ReqBody> Service<Request<ReqBody>> for AddOrigin<T>
3030
where
3131
T: Service<Request<ReqBody>>,
3232
T::Future: Send + 'static,
33-
T::Error: Into<crate::Error>,
33+
T::Error: Into<crate::BoxError>,
3434
{
3535
type Response = T::Response;
36-
type Error = crate::Error;
36+
type Error = crate::BoxError;
3737
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
3838

3939
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {

tonic/src/transport/channel/service/connection.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ use tower::{
2121
use tower_service::Service;
2222

2323
pub(crate) struct Connection {
24-
inner: BoxService<Request<BoxBody>, Response<BoxBody>, crate::Error>,
24+
inner: BoxService<Request<BoxBody>, Response<BoxBody>, crate::BoxError>,
2525
}
2626

2727
impl Connection {
2828
fn new<C>(connector: C, endpoint: Endpoint, is_lazy: bool) -> Self
2929
where
3030
C: Service<Uri> + Send + 'static,
31-
C::Error: Into<crate::Error> + Send,
31+
C::Error: Into<crate::BoxError> + Send,
3232
C::Future: Send,
3333
C::Response: rt::Read + rt::Write + Unpin + Send + 'static,
3434
{
@@ -77,10 +77,13 @@ impl Connection {
7777
}
7878
}
7979

80-
pub(crate) async fn connect<C>(connector: C, endpoint: Endpoint) -> Result<Self, crate::Error>
80+
pub(crate) async fn connect<C>(
81+
connector: C,
82+
endpoint: Endpoint,
83+
) -> Result<Self, crate::BoxError>
8184
where
8285
C: Service<Uri> + Send + 'static,
83-
C::Error: Into<crate::Error> + Send,
86+
C::Error: Into<crate::BoxError> + Send,
8487
C::Future: Unpin + Send,
8588
C::Response: rt::Read + rt::Write + Unpin + Send + 'static,
8689
{
@@ -90,7 +93,7 @@ impl Connection {
9093
pub(crate) fn lazy<C>(connector: C, endpoint: Endpoint) -> Self
9194
where
9295
C: Service<Uri> + Send + 'static,
93-
C::Error: Into<crate::Error> + Send,
96+
C::Error: Into<crate::BoxError> + Send,
9497
C::Future: Send,
9598
C::Response: rt::Read + rt::Write + Unpin + Send + 'static,
9699
{
@@ -100,7 +103,7 @@ impl Connection {
100103

101104
impl Service<Request<BoxBody>> for Connection {
102105
type Response = Response<BoxBody>;
103-
type Error = crate::Error;
106+
type Error = crate::BoxError;
104107
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
105108

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

139142
impl tower::Service<Request<BoxBody>> for SendRequest {
140143
type Response = Response<BoxBody>;
141-
type Error = crate::Error;
144+
type Error = crate::BoxError;
142145
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
143146

144147
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
@@ -171,12 +174,12 @@ impl<C> MakeSendRequestService<C> {
171174
impl<C> tower::Service<Uri> for MakeSendRequestService<C>
172175
where
173176
C: Service<Uri> + Send + 'static,
174-
C::Error: Into<crate::Error> + Send,
177+
C::Error: Into<crate::BoxError> + Send,
175178
C::Future: Send,
176179
C::Response: rt::Read + rt::Write + Unpin + Send,
177180
{
178181
type Response = SendRequest;
179-
type Error = crate::Error;
182+
type Error = crate::BoxError;
180183
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
181184

182185
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {

tonic/src/transport/channel/service/connector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ where
3535
C: Service<Uri>,
3636
C::Response: rt::Read + rt::Write + Unpin + Send + 'static,
3737
C::Future: Send + 'static,
38-
crate::Error: From<C::Error> + Send + 'static,
38+
crate::BoxError: From<C::Error> + Send + 'static,
3939
{
4040
type Response = BoxedIo;
4141
type Error = ConnectError;
@@ -69,7 +69,7 @@ where
6969
};
7070
}
7171

72-
Ok::<_, crate::Error>(BoxedIo::new(io))
72+
Ok::<_, crate::BoxError>(BoxedIo::new(io))
7373
}
7474
.await
7575
.map_err(ConnectError)

0 commit comments

Comments
 (0)