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 1 commit
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.

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use lambda_http::{handler, lambda, IntoResponse, Request, RequestExt, Response};

type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
use lambda_http::{handler, lambda, Error, IntoResponse, Request, RequestExt, Response};

#[tokio::main]
async fn main() -> Result<(), Error> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use lambda_http::{lambda, IntoResponse, Request};

type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
use lambda_http::{lambda, Error, IntoResponse, Request};

#[lambda(http)]
#[tokio::main]
Expand Down
4 changes: 1 addition & 3 deletions lambda-http/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ impl Error for PayloadError {
/// as well as `{"x":1, "y":2}` respectively.
///
/// ```rust,no_run
/// use lambda_http::{handler, lambda, Body, IntoResponse, Request, Response, RequestExt};
/// use lambda_http::{handler, lambda, Error, Body, IntoResponse, Request, Response, RequestExt};
/// use serde_derive::Deserialize;
///
/// type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
///
/// #[derive(Debug,Deserialize,Default)]
/// struct Args {
/// #[serde(default)]
Expand Down
20 changes: 6 additions & 14 deletions lambda-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
//! The full body of your `main` function will be executed on **every** invocation of your lambda task.
//!
//! ```rust,no_run
//! use lambda_http::{lambda, Request, IntoResponse};
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
//! use lambda_http::{lambda, Error, Request, IntoResponse};
//!
//! #[lambda(http)]
//! #[tokio::main]
Expand All @@ -39,8 +38,7 @@
//! Depending on the runtime cost of your dependency bootstrapping, this can reduce the overall latency of your functions execution path.
//!
//! ```rust,no_run
//! use lambda_http::{handler, lambda};
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
//! use lambda_http::{handler, lambda, Error};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Error> {
Expand All @@ -58,8 +56,7 @@
//! with the [`RequestExt`](trait.RequestExt.html) trait.
//!
//! ```rust,no_run
//! use lambda_http::{handler, lambda, IntoResponse, Request, RequestExt};
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
//! use lambda_http::{handler, lambda, Error, IntoResponse, Request, RequestExt};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Error> {
Expand Down Expand Up @@ -87,7 +84,7 @@ extern crate maplit;

pub use http::{self, Response};
use lambda::Handler as LambdaHandler;
pub use lambda::{self};
pub use lambda::{self, Error};
pub use lambda_attributes::lambda;
//pub use lambda_http_attributes::lambda_http;
mod body;
Expand All @@ -98,15 +95,11 @@ 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>;

/// 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 +127,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"
4 changes: 1 addition & 3 deletions lambda/examples/hello-with-ctx.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use lambda::lambda;
use lambda::{lambda, Error};
use serde_json::Value;

type Error = Box<dyn std::error::Error + Send + Sync + 'static>;

#[lambda]
#[tokio::main]
async fn main(event: Value) -> Result<Value, Error> {
Expand Down
4 changes: 1 addition & 3 deletions lambda/examples/hello-without-macro.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use lambda::handler_fn;
use lambda::{handler_fn, Error};
use serde_json::Value;

type Error = Box<dyn std::error::Error + Send + Sync + 'static>;

#[tokio::main]
async fn main() -> Result<(), Error> {
let func = handler_fn(func);
Expand Down
4 changes: 1 addition & 3 deletions lambda/examples/hello.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use lambda::lambda;
use lambda::{lambda, Error};
use serde_json::Value;

type Error = Box<dyn std::error::Error + Send + Sync + 'static>;

#[lambda]
#[tokio::main]
async fn main(event: Value) -> Result<Value, Error> {
Expand Down
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
14 changes: 6 additions & 8 deletions lambda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,16 @@
//! of [`lambda::LambdaCtx`].
//!
//! ```no_run
//! use lambda::lambda;
//! use lambda::{lambda, Error};
//! use serde_json::Value;
//!
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
//!
//! #[lambda]
//! #[tokio::main]
//! async fn main(event: Value) -> Result<Value, Error> {
//! Ok(event)
//! }
//! ```
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 +55,9 @@ mod types;
use requests::{EventCompletionRequest, EventErrorRequest, IntoRequest, NextEventRequest};
use types::Diagnostic;

/// Error type that lambdas may result in
pub 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 +119,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,11 +134,9 @@ where
///
/// # Example
/// ```no_run
/// use lambda::handler_fn;
/// use lambda::{handler_fn, Error};
/// use serde_json::Value;
///
/// type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Error> {
/// let func = handler_fn(func);
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