Skip to content

Commit 7347c58

Browse files
authored
Remove PollError from server type parameters (#2457)
## Motivation and Context #2444 ## Description Remove `PollError` from the implementation and documentation.
1 parent 840221d commit 7347c58

File tree

6 files changed

+66
-88
lines changed

6 files changed

+66
-88
lines changed

CHANGELOG.next.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,13 @@ author = "david-perez"
105105
references = ["smithy-rs#2676", "smithy-rs#2685"]
106106
meta = { "breaking" = true, "tada" = false, "bug" = false }
107107

108+
[[smithy-rs]]
109+
message = """Remove `PollError` from an operations `Service::Error`.
110+
111+
Any [`tower::Service`](https://docs.rs/tower/latest/tower/trait.Service.html) provided to
112+
[`Operation::from_service`](https://docs.rs/aws-smithy-http-server/latest/aws_smithy_http_server/operation/struct.Operation.html#method.from_service)
113+
no longer requires `Service::Error = OperationError<Op::Error, PollError>`, instead requiring just `Service::Error = Op::Error`.
114+
"""
115+
references = ["smithy-rs#2457"]
116+
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" }
117+
author = "hlbarber"

rust-runtime/aws-smithy-http-server/src/operation/handler.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ use std::{
1010
task::{Context, Poll},
1111
};
1212

13-
use futures_util::{
14-
future::{Map, MapErr},
15-
FutureExt, TryFutureExt,
16-
};
13+
use futures_util::{future::Map, FutureExt};
1714
use tower::Service;
1815

19-
use super::{OperationError, OperationShape};
16+
use super::OperationShape;
2017

2118
/// A utility trait used to provide an even interface for all operation handlers.
2219
///
@@ -143,14 +140,14 @@ where
143140
H: Handler<Op, Exts>,
144141
{
145142
type Response = Op::Output;
146-
type Error = OperationError<Op::Error, Infallible>;
147-
type Future = MapErr<H::Future, fn(Op::Error) -> Self::Error>;
143+
type Error = Op::Error;
144+
type Future = H::Future;
148145

149146
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
150147
Poll::Ready(Ok(()))
151148
}
152149

153150
fn call(&mut self, (input, exts): (Op::Input, Exts)) -> Self::Future {
154-
self.handler.call(input, exts).map_err(OperationError::Model)
151+
self.handler.call(input, exts)
155152
}
156153
}

rust-runtime/aws-smithy-http-server/src/operation/mod.rs

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,13 @@
8484
//! ## [`OperationService`]
8585
//!
8686
//! Similarly, the [`OperationService`] trait is implemented by all `Service<(Op::Input, ...)>` with
87-
//! `Response = Op::Output`, and `Error = OperationError<Op::Error, PollError>`.
88-
//!
89-
//! We use [`OperationError`], with a `PollError` not constrained by the model, to allow the user to provide a custom
90-
//! [`Service::poll_ready`](tower::Service::poll_ready) implementation.
87+
//! `Response = Op::Output`, and `Error = Op::Error`.
9188
//!
9289
//! The following are examples of [`Service`](tower::Service)s which implement [`OperationService`]:
9390
//!
94-
//! - `Service<CartIdentifier, Response = ShoppingCart, Error = OperationError<Infallible, Infallible>>`.
95-
//! - `Service<(CartIdentifier, Extension<Context>), Response = ShoppingCart, Error = OperationError<GetShoppingCartError, Infallible>>`.
96-
//! - `Service<(CartIdentifier, Extension<Context>, Extension<ExtraContext>), Response = ShoppingCart, Error = OperationError<GetShoppingCartError, PollError>)`.
91+
//! - `Service<CartIdentifier, Response = ShoppingCart, Error = Infallible>`.
92+
//! - `Service<(CartIdentifier, Extension<Context>), Response = ShoppingCart, Error = GetShoppingCartError>`.
93+
//! - `Service<(CartIdentifier, Extension<Context>, Extension<ExtraContext>), Response = ShoppingCart, Error = GetShoppingCartError)`.
9794
//!
9895
//! Notice the parallels between [`OperationService`] and [`Handler`].
9996
//!
@@ -116,7 +113,7 @@
116113
//! # type Output = ShoppingCart;
117114
//! # type Error = GetShoppingError;
118115
//! # }
119-
//! # type OpFuture = std::future::Ready<Result<ShoppingCart, OperationError<GetShoppingError, PollError>>>;
116+
//! # type OpFuture = std::future::Ready<Result<ShoppingCart, GetShoppingError>>;
120117
//! // Construction of an `Operation` from a `Handler`.
121118
//!
122119
//! async fn op_handler(input: CartIdentifier) -> Result<ShoppingCart, GetShoppingError> {
@@ -127,13 +124,11 @@
127124
//!
128125
//! // Construction of an `Operation` from a `Service`.
129126
//!
130-
//! pub struct PollError;
131-
//!
132127
//! pub struct OpService;
133128
//!
134129
//! impl Service<CartIdentifier> for OpService {
135130
//! type Response = ShoppingCart;
136-
//! type Error = OperationError<GetShoppingError, PollError>;
131+
//! type Error = GetShoppingError;
137132
//! type Future = OpFuture;
138133
//!
139134
//! fn poll_ready(&mut self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
@@ -155,19 +150,13 @@
155150
//!
156151
//! Both [`Handler`] and [`OperationService`] accept and return Smithy model structures. After an [`Operation`] is
157152
//! constructed they are converted to a canonical form
158-
//! `Service<(Op::Input, Exts), Response = Op::Output, Error = OperationError<Op::Error, PollError>>`. The
153+
//! `Service<(Op::Input, Exts), Response = Op::Output, Error = Op::Error>`. The
159154
//! [`UpgradeLayer`] acts upon such services by converting them to
160-
//! `Service<http::Request, Response = http::Response, Error = PollError>`.
155+
//! `Service<http::Request, Response = http::Response, Error = Infallible>`.
161156
//!
162-
//! Note that the `PollError` is still exposed, for two reasons:
163-
//!
164-
//! - Smithy is agnostic to `PollError` and therefore we have no prescribed way to serialize it to a [`http::Response`]
165-
//! , unlike the operation errors.
166-
//! - The intention of `PollError` is to signal that the underlying service is no longer able to take requests, so
167-
//! should be discarded. See [`Service::poll_ready`](tower::Service::poll_ready).
168157
//!
169158
//! The [`UpgradeLayer`] and it's [`Layer::Service`](tower::Layer::Service) [`Upgrade`] are both parameterized by a
170-
//! protocol. This allows for upgrading to `Service<http::Request, Response = http::Response, Error = PollError>` to be
159+
//! protocol. This allows for upgrading to `Service<http::Request, Response = http::Response, Error = Infallible>` to be
171160
//! protocol dependent.
172161
//!
173162
//! The [`Operation::upgrade`] will apply [`UpgradeLayer`] to `S` then apply the [`Layer`](tower::Layer) `L`. The
@@ -208,15 +197,15 @@ impl<S, L> Operation<S, L> {
208197
}
209198
}
210199

211-
impl<Op, S, PollError> Operation<Normalize<Op, S, PollError>> {
200+
impl<Op, S> Operation<Normalize<Op, S>> {
212201
/// Creates an [`Operation`] from a [`Service`](tower::Service).
213202
pub fn from_service<Exts>(inner: S) -> Self
214203
where
215204
Op: OperationShape,
216-
S: OperationService<Op, Exts, PollError>,
205+
S: OperationService<Op, Exts>,
217206
{
218207
Self {
219-
inner: inner.canonicalize(),
208+
inner: inner.normalize(),
220209
layer: Identity::new(),
221210
}
222211
}
@@ -235,12 +224,3 @@ impl<Op, H> Operation<IntoService<Op, H>> {
235224
}
236225
}
237226
}
238-
239-
/// The operation [`Service`](tower::Service) has two classes of failure modes - those specified by the Smithy model
240-
/// and those associated with [`Service::poll_ready`](tower::Service::poll_ready).
241-
pub enum OperationError<ModelError, PollError> {
242-
/// An error modelled by the Smithy model occurred.
243-
Model(ModelError),
244-
/// A [`Service::poll_ready`](tower::Service::poll_ready) failure occurred.
245-
PollReady(PollError),
246-
}

rust-runtime/aws-smithy-http-server/src/operation/operation_service.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010

1111
use tower::Service;
1212

13-
use super::{OperationError, OperationShape};
13+
use super::OperationShape;
1414

1515
/// A utility trait used to provide an even interface for all operation services.
1616
///
@@ -19,8 +19,7 @@ use super::{OperationError, OperationShape};
1919
/// [`IntoService`](super::IntoService).
2020
///
2121
/// See [`operation`](crate::operation) documentation for more info.
22-
pub trait OperationService<Op, Exts, PollError>:
23-
Service<Self::Normalized, Response = Op::Output, Error = OperationError<Op::Error, PollError>>
22+
pub trait OperationService<Op, Exts>: Service<Self::Normalized, Response = Op::Output, Error = Op::Error>
2423
where
2524
Op: OperationShape,
2625
{
@@ -31,10 +30,10 @@ where
3130
}
3231

3332
// `Service<Op::Input>`
34-
impl<Op, S, PollError> OperationService<Op, (), PollError> for S
33+
impl<Op, S> OperationService<Op, ()> for S
3534
where
3635
Op: OperationShape,
37-
S: Service<Op::Input, Response = Op::Output, Error = OperationError<Op::Error, PollError>>,
36+
S: Service<Op::Input, Response = Op::Output, Error = Op::Error>,
3837
{
3938
type Normalized = Op::Input;
4039

@@ -44,10 +43,10 @@ where
4443
}
4544

4645
// `Service<(Op::Input, Ext0)>`
47-
impl<Op, Ext0, S, PollError> OperationService<Op, (Ext0,), PollError> for S
46+
impl<Op, Ext0, S> OperationService<Op, (Ext0,)> for S
4847
where
4948
Op: OperationShape,
50-
S: Service<(Op::Input, Ext0), Response = Op::Output, Error = OperationError<Op::Error, PollError>>,
49+
S: Service<(Op::Input, Ext0), Response = Op::Output, Error = Op::Error>,
5150
{
5251
type Normalized = (Op::Input, Ext0);
5352

@@ -57,10 +56,10 @@ where
5756
}
5857

5958
// `Service<(Op::Input, Ext0, Ext1)>`
60-
impl<Op, Ext0, Ext1, S, PollError> OperationService<Op, (Ext0, Ext1), PollError> for S
59+
impl<Op, Ext0, Ext1, S> OperationService<Op, (Ext0, Ext1)> for S
6160
where
6261
Op: OperationShape,
63-
S: Service<(Op::Input, Ext0, Ext1), Response = Op::Output, Error = OperationError<Op::Error, PollError>>,
62+
S: Service<(Op::Input, Ext0, Ext1), Response = Op::Output, Error = Op::Error>,
6463
{
6564
type Normalized = (Op::Input, Ext0, Ext1);
6665

@@ -70,55 +69,52 @@ where
7069
}
7170

7271
/// An extension trait of [`OperationService`].
73-
pub trait OperationServiceExt<Op, Exts, PollError>: OperationService<Op, Exts, PollError>
72+
pub trait OperationServiceExt<Op, Exts>: OperationService<Op, Exts>
7473
where
7574
Op: OperationShape,
7675
{
7776
/// Convert the [`OperationService`] into a canonicalized [`Service`].
78-
fn canonicalize(self) -> Normalize<Op, Self, PollError>
77+
fn normalize(self) -> Normalize<Op, Self>
7978
where
8079
Self: Sized,
8180
{
8281
Normalize {
8382
inner: self,
8483
_operation: PhantomData,
85-
_poll_error: PhantomData,
8684
}
8785
}
8886
}
8987

90-
impl<F, Op, Exts, PollError> OperationServiceExt<Op, Exts, PollError> for F
88+
impl<F, Op, Exts> OperationServiceExt<Op, Exts> for F
9189
where
9290
Op: OperationShape,
93-
F: OperationService<Op, Exts, PollError>,
91+
F: OperationService<Op, Exts>,
9492
{
9593
}
9694

9795
/// A [`Service`] normalizing the request type of a [`OperationService`].
9896
#[derive(Debug)]
99-
pub struct Normalize<Op, S, PollError> {
97+
pub struct Normalize<Op, S> {
10098
inner: S,
10199
_operation: PhantomData<Op>,
102-
_poll_error: PhantomData<PollError>,
103100
}
104101

105-
impl<Op, S, PollError> Clone for Normalize<Op, S, PollError>
102+
impl<Op, S> Clone for Normalize<Op, S>
106103
where
107104
S: Clone,
108105
{
109106
fn clone(&self) -> Self {
110107
Self {
111108
inner: self.inner.clone(),
112109
_operation: PhantomData,
113-
_poll_error: PhantomData,
114110
}
115111
}
116112
}
117113

118-
impl<Op, S, Exts, PollError> Service<(Op::Input, Exts)> for Normalize<Op, S, PollError>
114+
impl<Op, S, Exts> Service<(Op::Input, Exts)> for Normalize<Op, S>
119115
where
120116
Op: OperationShape,
121-
S: OperationService<Op, Exts, PollError>,
117+
S: OperationService<Op, Exts>,
122118
{
123119
type Response = S::Response;
124120
type Error = S::Error;

rust-runtime/aws-smithy-http-server/src/operation/shape.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ pub trait OperationShapeExt: OperationShape {
3333
}
3434

3535
/// Creates a new [`Operation`] for well-formed [`Service`](tower::Service)s.
36-
fn from_service<S, Exts, PollError>(svc: S) -> Operation<Normalize<Self, S, PollError>>
36+
fn from_service<S, Exts>(svc: S) -> Operation<Normalize<Self, S>>
3737
where
38-
S: OperationService<Self, Exts, PollError>,
38+
S: OperationService<Self, Exts>,
3939
Self: Sized,
4040
{
4141
Operation::from_service(svc)

0 commit comments

Comments
 (0)