Skip to content

Commit ed3fd16

Browse files
authored
replace anyhow with std error and an type alias (awslabs#231)
Resolves awslabs#229.
1 parent 91d2a60 commit ed3fd16

File tree

9 files changed

+24
-29
lines changed

9 files changed

+24
-29
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.

lambda-http/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
//!
2424
//! ```rust,no_run
2525
//! use lambda_http::{lambda, Request, IntoResponse};
26+
//!
2627
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
2728
//!
2829
//! #[lambda(http)]
@@ -40,6 +41,7 @@
4041
//!
4142
//! ```rust,no_run
4243
//! use lambda_http::{handler, lambda};
44+
//!
4345
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
4446
//!
4547
//! #[tokio::main]
@@ -59,6 +61,7 @@
5961
//!
6062
//! ```rust,no_run
6163
//! use lambda_http::{handler, lambda, IntoResponse, Request, RequestExt};
64+
//!
6265
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
6366
//!
6467
//! #[tokio::main]
@@ -89,7 +92,7 @@ pub use http::{self, Response};
8992
use lambda::Handler as LambdaHandler;
9093
pub use lambda::{self};
9194
pub use lambda_attributes::lambda;
92-
//pub use lambda_http_attributes::lambda_http;
95+
9396
mod body;
9497
pub mod ext;
9598
pub mod request;
@@ -98,14 +101,13 @@ mod strmap;
98101
pub use crate::{body::Body, ext::RequestExt, response::IntoResponse, strmap::StrMap};
99102
use crate::{request::LambdaRequest, response::LambdaResponse};
100103
use std::{
101-
error::Error,
102-
fmt,
103104
future::Future,
104105
pin::Pin,
105106
task::{Context, Poll},
106107
};
107108

108-
type Err = Box<dyn Error + Send + Sync + 'static>;
109+
/// Error type that lambdas may result in
110+
pub(crate) type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
109111

110112
/// Type alias for `http::Request`s with a fixed [`Body`](enum.Body.html) type
111113
pub type Request = http::Request<Body>;
@@ -134,11 +136,10 @@ impl<F, R, Fut> Handler for F
134136
where
135137
F: FnMut(Request) -> Fut,
136138
R: IntoResponse,
137-
Fut: Future<Output = Result<R, Err>> + Send + 'static,
138-
Err: Into<Box<dyn Error + Send + Sync + 'static>> + fmt::Debug,
139+
Fut: Future<Output = Result<R, Error>> + Send + 'static,
139140
{
140141
type Response = R;
141-
type Error = Err;
142+
type Error = Error;
142143
type Fut = Fut;
143144
fn call(&mut self, event: Request) -> Self::Fut {
144145
(*self)(event)

lambda/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@ futures = "0.3"
2525
tracing = "0.1.13"
2626
tracing-futures = "0.2.3"
2727
tracing-error = "0.1.2"
28-
anyhow = "1.0.27"

lambda/src/client.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
use crate::requests::{IntoResponse, NextEventResponse};
2-
use anyhow::Error;
1+
use crate::{
2+
requests::{IntoResponse, NextEventResponse},
3+
Error,
4+
};
35
use http::{
46
uri::{PathAndQuery, Scheme},
57
HeaderValue, Method, Request, Response, StatusCode, Uri,
@@ -172,8 +174,8 @@ mod endpoint_tests {
172174
requests::{EventCompletionRequest, EventErrorRequest, IntoRequest, NextEventRequest},
173175
simulated::SimulatedConnector,
174176
types::Diagnostic,
177+
Error,
175178
};
176-
use anyhow::Error;
177179
use http::{HeaderValue, StatusCode, Uri};
178180
use std::convert::TryFrom;
179181
use tokio::sync;
@@ -203,7 +205,7 @@ mod endpoint_tests {
203205
tx.send(()).expect("Receiver has been dropped");
204206
match server.await {
205207
Ok(_) => Ok(()),
206-
Err(e) if e.is_panic() => return Err::<(), anyhow::Error>(e.into()),
208+
Err(e) if e.is_panic() => return Err::<(), Error>(e.into()),
207209
Err(_) => unreachable!("This branch shouldn't be reachable"),
208210
}
209211
}
@@ -235,7 +237,7 @@ mod endpoint_tests {
235237
tx.send(()).expect("Receiver has been dropped");
236238
match server.await {
237239
Ok(_) => Ok(()),
238-
Err(e) if e.is_panic() => return Err::<(), anyhow::Error>(e.into()),
240+
Err(e) if e.is_panic() => return Err::<(), Error>(e.into()),
239241
Err(_) => unreachable!("This branch shouldn't be reachable"),
240242
}
241243
}
@@ -269,7 +271,7 @@ mod endpoint_tests {
269271
tx.send(()).expect("Receiver has been dropped");
270272
match server.await {
271273
Ok(_) => Ok(()),
272-
Err(e) if e.is_panic() => return Err::<(), anyhow::Error>(e.into()),
274+
Err(e) if e.is_panic() => return Err::<(), Error>(e.into()),
273275
Err(_) => unreachable!("This branch shouldn't be reachable"),
274276
}
275277
}

lambda/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
//! of [`lambda::LambdaCtx`].
2626
//!
2727
//! ```no_run
28-
//! use lambda::lambda;
28+
//! use lambda::{lambda};
2929
//! use serde_json::Value;
3030
//!
3131
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
@@ -37,7 +37,6 @@
3737
//! }
3838
//! ```
3939
pub use crate::types::LambdaCtx;
40-
use anyhow::Error;
4140
use client::Client;
4241
use futures::stream::{Stream, StreamExt};
4342
use genawaiter::{sync::gen, yield_};
@@ -58,6 +57,9 @@ mod types;
5857
use requests::{EventCompletionRequest, EventErrorRequest, IntoRequest, NextEventRequest};
5958
use types::Diagnostic;
6059

60+
/// Error type that lambdas may result in
61+
pub(crate) type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
62+
6163
/// Configuration derived from environment variables.
6264
#[derive(Debug, Default, Clone, PartialEq)]
6365
pub struct Config {
@@ -119,7 +121,7 @@ impl<F, A, B, Error, Fut> Handler<A, B> for HandlerFn<F>
119121
where
120122
F: Fn(A) -> Fut,
121123
Fut: Future<Output = Result<B, Error>> + Send,
122-
Error: Into<Box<dyn std::error::Error + Send + Sync + 'static>> + fmt::Debug,
124+
Error: Into<Error> + fmt::Debug,
123125
{
124126
type Error = Error;
125127
type Fut = Fut;
@@ -134,7 +136,7 @@ where
134136
///
135137
/// # Example
136138
/// ```no_run
137-
/// use lambda::handler_fn;
139+
/// use lambda::{handler_fn};
138140
/// use serde_json::Value;
139141
///
140142
/// type Error = Box<dyn std::error::Error + Send + Sync + 'static>;

lambda/src/requests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::types::Diagnostic;
2-
use anyhow::Error;
1+
use crate::{types::Diagnostic, Error};
32
use http::{Method, Request, Response, Uri};
43
use hyper::Body;
54
use serde::Serialize;

lambda/src/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::Config;
2-
use anyhow::Error;
1+
use crate::{Config, Error};
32
use http::HeaderMap;
43
use serde::{Deserialize, Serialize};
54
use std::{collections::HashMap, convert::TryFrom};

0 commit comments

Comments
 (0)