From a7fafce363eaf4e8af60be84ba3c57312004cadb Mon Sep 17 00:00:00 2001 From: Colton Weaver Date: Thu, 11 Mar 2021 17:55:31 -0800 Subject: [PATCH 1/5] Making Error type public so that consumers don't have to create their own type alias --- lambda-http/src/lib.rs | 12 +++--------- lambda-runtime/examples/error-handling.rs | 7 ++----- lambda-runtime/src/lib.rs | 2 +- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/lambda-http/src/lib.rs b/lambda-http/src/lib.rs index 2351383e..ac2b164c 100644 --- a/lambda-http/src/lib.rs +++ b/lambda-http/src/lib.rs @@ -17,9 +17,7 @@ //! your function's execution path. //! //! ```rust,no_run -//! use lambda_http::{handler, lambda_runtime}; -//! -//! type Error = Box; +//! use lambda_http::{handler, lambda_runtime::{self, Error}}; //! //! #[tokio::main] //! async fn main() -> Result<(), Error> { @@ -36,9 +34,7 @@ //! with the [`RequestExt`](trait.RequestExt.html) trait. //! //! ```rust,no_run -//! use lambda_http::{handler, lambda_runtime::{self, Context}, IntoResponse, Request, RequestExt}; -//! -//! type Error = Box; +//! use lambda_http::{handler, lambda_runtime::{self, Context, Error}, IntoResponse, Request, RequestExt}; //! //! #[tokio::main] //! async fn main() -> Result<(), Error> { @@ -67,6 +63,7 @@ extern crate maplit; pub use http::{self, Response}; use lambda_runtime::Handler as LambdaHandler; +use lambda_runtime::Error as Error; pub use lambda_runtime::{self, Context}; mod body; @@ -85,9 +82,6 @@ use std::{ task::{Context as TaskContext, Poll}, }; -/// Error type that lambdas may result in -pub(crate) type Error = Box; - /// Type alias for `http::Request`s with a fixed [`Body`](enum.Body.html) type pub type Request = http::Request; diff --git a/lambda-runtime/examples/error-handling.rs b/lambda-runtime/examples/error-handling.rs index f5ba2474..8c6fbcff 100644 --- a/lambda-runtime/examples/error-handling.rs +++ b/lambda-runtime/examples/error-handling.rs @@ -6,9 +6,6 @@ use serde_json::{json, Value}; use simple_logger::SimpleLogger; use std::fs::File; -/// A shorthand for `Box` type required by aws-lambda-rust-runtime. -pub type Error = Box; - /// A simple Lambda request structure with just one field /// that tells the Lambda what is expected of it. #[derive(Deserialize)] @@ -53,7 +50,7 @@ impl std::fmt::Display for CustomError { } #[tokio::main] -async fn main() -> Result<(), Error> { +async fn main() -> Result<(), lambda_runtime::Error> { // The runtime logging can be enabled here by initializing `log` with `simple_logger` // or another compatible crate. The runtime is using `tracing` internally. // You can comment out the `simple_logger` init line and uncomment the following block to @@ -78,7 +75,7 @@ async fn main() -> Result<(), Error> { } /// The actual handler of the Lambda request. -pub(crate) async fn func(event: Value, ctx: lambda_runtime::Context) -> Result { +pub(crate) async fn func(event: Value, ctx: lambda_runtime::Context) -> Result { // check what action was requested match serde_json::from_value::(event)?.event_type { EventType::SimpleError => { diff --git a/lambda-runtime/src/lib.rs b/lambda-runtime/src/lib.rs index e05edbf4..a78da826 100644 --- a/lambda-runtime/src/lib.rs +++ b/lambda-runtime/src/lib.rs @@ -31,7 +31,7 @@ use requests::{EventCompletionRequest, EventErrorRequest, IntoRequest, NextEvent use types::Diagnostic; /// Error type that lambdas may result in -pub(crate) type Error = Box; +pub type Error = Box; /// Configuration derived from environment variables. #[derive(Debug, Default, Clone, PartialEq)] From b932b756c55c8dfd0774c08096b4a53ed158b28b Mon Sep 17 00:00:00 2001 From: Colton Weaver Date: Thu, 11 Mar 2021 18:05:53 -0800 Subject: [PATCH 2/5] Missed usage in example --- lambda-runtime/examples/basic.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lambda-runtime/examples/basic.rs b/lambda-runtime/examples/basic.rs index 999efdcc..756f4c92 100644 --- a/lambda-runtime/examples/basic.rs +++ b/lambda-runtime/examples/basic.rs @@ -6,10 +6,6 @@ use log::LevelFilter; use serde::{Deserialize, Serialize}; use simple_logger::SimpleLogger; -/// A shorthand for `Box` -/// type required by aws-lambda-rust-runtime. -pub type Error = Box; - /// This is also a made-up example. Requests come into the runtime as unicode /// strings in json format, which can map to any structure that implements `serde::Deserialize` /// The runtime pays no attention to the contents of the request payload. @@ -29,7 +25,7 @@ struct Response { } #[tokio::main] -async fn main() -> Result<(), Error> { +async fn main() -> Result<(), lambda_runtime::Error> { // required to enable CloudWatch error logging by the runtime // can be replaced with any other method of initializing `log` SimpleLogger::new().with_level(LevelFilter::Info).init().unwrap(); From 164b439a4749f4ae291dd897720c4bd8d25454d2 Mon Sep 17 00:00:00 2001 From: Colton Weaver Date: Thu, 11 Mar 2021 18:06:39 -0800 Subject: [PATCH 3/5] Rust fmt changes --- lambda-http/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lambda-http/src/lib.rs b/lambda-http/src/lib.rs index ac2b164c..7fdcca56 100644 --- a/lambda-http/src/lib.rs +++ b/lambda-http/src/lib.rs @@ -62,9 +62,8 @@ extern crate maplit; pub use http::{self, Response}; -use lambda_runtime::Handler as LambdaHandler; -use lambda_runtime::Error as Error; pub use lambda_runtime::{self, Context}; +use lambda_runtime::{Error, Handler as LambdaHandler}; mod body; pub mod ext; From 9a16b9575ea7f8b219fe9d660c8d0e01daa35754 Mon Sep 17 00:00:00 2001 From: Colton Weaver Date: Thu, 11 Mar 2021 18:10:20 -0800 Subject: [PATCH 4/5] Missed example use. --- lambda-runtime/examples/basic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda-runtime/examples/basic.rs b/lambda-runtime/examples/basic.rs index 756f4c92..4922ca48 100644 --- a/lambda-runtime/examples/basic.rs +++ b/lambda-runtime/examples/basic.rs @@ -35,7 +35,7 @@ async fn main() -> Result<(), lambda_runtime::Error> { Ok(()) } -pub(crate) async fn my_handler(event: Request, ctx: Context) -> Result { +pub(crate) async fn my_handler(event: Request, ctx: Context) -> Result { // extract some useful info from the request let command = event.command; From c7f7c58a6233234a0d2b5cd8f3b4c7a54681ae60 Mon Sep 17 00:00:00 2001 From: Colton Weaver Date: Thu, 11 Mar 2021 18:27:53 -0800 Subject: [PATCH 5/5] Changing lambda_runtime::Error references to just Error and including in imports instead. --- lambda-runtime/examples/basic.rs | 6 +++--- lambda-runtime/examples/error-handling.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lambda-runtime/examples/basic.rs b/lambda-runtime/examples/basic.rs index 4922ca48..d74e10de 100644 --- a/lambda-runtime/examples/basic.rs +++ b/lambda-runtime/examples/basic.rs @@ -1,7 +1,7 @@ // This example requires the following input to succeed: // { "command": "do something" } -use lambda_runtime::{handler_fn, Context}; +use lambda_runtime::{handler_fn, Context, Error}; use log::LevelFilter; use serde::{Deserialize, Serialize}; use simple_logger::SimpleLogger; @@ -25,7 +25,7 @@ struct Response { } #[tokio::main] -async fn main() -> Result<(), lambda_runtime::Error> { +async fn main() -> Result<(), Error> { // required to enable CloudWatch error logging by the runtime // can be replaced with any other method of initializing `log` SimpleLogger::new().with_level(LevelFilter::Info).init().unwrap(); @@ -35,7 +35,7 @@ async fn main() -> Result<(), lambda_runtime::Error> { Ok(()) } -pub(crate) async fn my_handler(event: Request, ctx: Context) -> Result { +pub(crate) async fn my_handler(event: Request, ctx: Context) -> Result { // extract some useful info from the request let command = event.command; diff --git a/lambda-runtime/examples/error-handling.rs b/lambda-runtime/examples/error-handling.rs index 8c6fbcff..a0683f21 100644 --- a/lambda-runtime/examples/error-handling.rs +++ b/lambda-runtime/examples/error-handling.rs @@ -1,5 +1,5 @@ /// See https://github.com/awslabs/aws-lambda-rust-runtime for more info on Rust runtime for AWS Lambda -use lambda_runtime::handler_fn; +use lambda_runtime::{handler_fn, Error}; use log::LevelFilter; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; @@ -50,7 +50,7 @@ impl std::fmt::Display for CustomError { } #[tokio::main] -async fn main() -> Result<(), lambda_runtime::Error> { +async fn main() -> Result<(), Error> { // The runtime logging can be enabled here by initializing `log` with `simple_logger` // or another compatible crate. The runtime is using `tracing` internally. // You can comment out the `simple_logger` init line and uncomment the following block to @@ -75,7 +75,7 @@ async fn main() -> Result<(), lambda_runtime::Error> { } /// The actual handler of the Lambda request. -pub(crate) async fn func(event: Value, ctx: lambda_runtime::Context) -> Result { +pub(crate) async fn func(event: Value, ctx: lambda_runtime::Context) -> Result { // check what action was requested match serde_json::from_value::(event)?.event_type { EventType::SimpleError => {