Skip to content

replace anyhow with std error and an type alias #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
15 changes: 8 additions & 7 deletions lambda-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
//!
//! ```rust,no_run
//! use lambda_http::{lambda, Request, IntoResponse};
//!
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
//!
//! #[lambda(http)]
Expand All @@ -40,6 +41,7 @@
//!
//! ```rust,no_run
//! use lambda_http::{handler, lambda};
//!
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
//!
//! #[tokio::main]
Expand All @@ -59,6 +61,7 @@
//!
//! ```rust,no_run
//! use lambda_http::{handler, lambda, IntoResponse, Request, RequestExt};
//!
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
//!
//! #[tokio::main]
Expand Down Expand Up @@ -89,7 +92,7 @@ pub use http::{self, Response};
use lambda::Handler as LambdaHandler;
pub use lambda::{self};
pub use lambda_attributes::lambda;
//pub use lambda_http_attributes::lambda_http;

mod body;
pub mod ext;
pub mod request;
Expand All @@ -98,14 +101,13 @@ mod strmap;
pub use crate::{body::Body, ext::RequestExt, response::IntoResponse, strmap::StrMap};
use crate::{request::LambdaRequest, response::LambdaResponse};
use std::{
error::Error,
fmt,
future::Future,
pin::Pin,
task::{Context, Poll},
};

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

/// Type alias for `http::Request`s with a fixed [`Body`](enum.Body.html) type
pub type Request = http::Request<Body>;
Expand Down Expand Up @@ -134,11 +136,10 @@ impl<F, R, Fut> Handler for F
where
F: FnMut(Request) -> Fut,
R: IntoResponse,
Fut: Future<Output = Result<R, Err>> + Send + 'static,
Err: Into<Box<dyn Error + Send + Sync + 'static>> + fmt::Debug,
Fut: Future<Output = Result<R, Error>> + Send + 'static,
{
type Response = R;
type Error = Err;
type Error = Error;
type Fut = Fut;
fn call(&mut self, event: Request) -> Self::Fut {
(*self)(event)
Expand Down
1 change: 0 additions & 1 deletion lambda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ futures = "0.3"
tracing = "0.1.13"
tracing-futures = "0.2.3"
tracing-error = "0.1.2"
anyhow = "1.0.27"
14 changes: 8 additions & 6 deletions lambda/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::requests::{IntoResponse, NextEventResponse};
use anyhow::Error;
use crate::{
requests::{IntoResponse, NextEventResponse},
Error,
};
use http::{
uri::{PathAndQuery, Scheme},
HeaderValue, Method, Request, Response, StatusCode, Uri,
Expand Down Expand Up @@ -172,8 +174,8 @@ mod endpoint_tests {
requests::{EventCompletionRequest, EventErrorRequest, IntoRequest, NextEventRequest},
simulated::SimulatedConnector,
types::Diagnostic,
Error,
};
use anyhow::Error;
use http::{HeaderValue, StatusCode, Uri};
use std::convert::TryFrom;
use tokio::sync;
Expand Down Expand Up @@ -203,7 +205,7 @@ mod endpoint_tests {
tx.send(()).expect("Receiver has been dropped");
match server.await {
Ok(_) => Ok(()),
Err(e) if e.is_panic() => return Err::<(), anyhow::Error>(e.into()),
Err(e) if e.is_panic() => return Err::<(), Error>(e.into()),
Err(_) => unreachable!("This branch shouldn't be reachable"),
}
}
Expand Down Expand Up @@ -235,7 +237,7 @@ mod endpoint_tests {
tx.send(()).expect("Receiver has been dropped");
match server.await {
Ok(_) => Ok(()),
Err(e) if e.is_panic() => return Err::<(), anyhow::Error>(e.into()),
Err(e) if e.is_panic() => return Err::<(), Error>(e.into()),
Err(_) => unreachable!("This branch shouldn't be reachable"),
}
}
Expand Down Expand Up @@ -269,7 +271,7 @@ mod endpoint_tests {
tx.send(()).expect("Receiver has been dropped");
match server.await {
Ok(_) => Ok(()),
Err(e) if e.is_panic() => return Err::<(), anyhow::Error>(e.into()),
Err(e) if e.is_panic() => return Err::<(), Error>(e.into()),
Err(_) => unreachable!("This branch shouldn't be reachable"),
}
}
Expand Down
10 changes: 6 additions & 4 deletions lambda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//! of [`lambda::LambdaCtx`].
//!
//! ```no_run
//! use lambda::lambda;
//! use lambda::{lambda};
//! use serde_json::Value;
//!
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
Expand All @@ -37,7 +37,6 @@
//! }
//! ```
pub use crate::types::LambdaCtx;
use anyhow::Error;
use client::Client;
use futures::stream::{Stream, StreamExt};
use genawaiter::{sync::gen, yield_};
Expand All @@ -58,6 +57,9 @@ mod types;
use requests::{EventCompletionRequest, EventErrorRequest, IntoRequest, NextEventRequest};
use types::Diagnostic;

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

/// Configuration derived from environment variables.
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Config {
Expand Down Expand Up @@ -119,7 +121,7 @@ impl<F, A, B, Error, Fut> Handler<A, B> for HandlerFn<F>
where
F: Fn(A) -> Fut,
Fut: Future<Output = Result<B, Error>> + Send,
Error: Into<Box<dyn std::error::Error + Send + Sync + 'static>> + fmt::Debug,
Error: Into<Error> + fmt::Debug,
{
type Error = Error;
type Fut = Fut;
Expand All @@ -134,7 +136,7 @@ where
///
/// # Example
/// ```no_run
/// use lambda::handler_fn;
/// use lambda::{handler_fn};
/// use serde_json::Value;
///
/// type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
Expand Down
3 changes: 1 addition & 2 deletions lambda/src/requests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::types::Diagnostic;
use anyhow::Error;
use crate::{types::Diagnostic, Error};
use http::{Method, Request, Response, Uri};
use hyper::Body;
use serde::Serialize;
Expand Down
3 changes: 1 addition & 2 deletions lambda/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::Config;
use anyhow::Error;
use crate::{Config, Error};
use http::HeaderMap;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, convert::TryFrom};
Expand Down