Skip to content

give better error when lambda fails to start #155

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 1 commit into from
Aug 6, 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
5 changes: 2 additions & 3 deletions Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ extension Lambda {
/// - body: Code to run within the context of the mock server. Typically this would be a Lambda.run function call.
///
/// - note: This API is designed stricly for local testing and is behind a DEBUG flag
@discardableResult
static func withLocalServer<Value>(invocationEndpoint: String? = nil, _ body: @escaping () -> Value) throws -> Value {
internal static func withLocalServer<Value>(invocationEndpoint: String? = nil, _ body: @escaping () -> Value) throws -> Value {
let server = LocalLambda.Server(invocationEndpoint: invocationEndpoint)
try server.start().wait()
defer { try! server.stop() } // FIXME:
defer { try! server.stop() }
return body()
}
}
Expand Down
10 changes: 6 additions & 4 deletions Sources/AWSLambdaRuntimeCore/Lambda+String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ extension Lambda {
///
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
public static func run(_ closure: @escaping StringClosure) {
self.run(closure: closure)
if case .failure(let error) = self.run(closure: closure) {
fatalError("\(error)")
}
}

/// An asynchronous Lambda Closure that takes a `String` and returns a `Result<Void, Error>` via a completion handler.
Expand All @@ -38,17 +40,17 @@ extension Lambda {
///
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
public static func run(_ closure: @escaping StringVoidClosure) {
self.run(closure: closure)
if case .failure(let error) = self.run(closure: closure) {
fatalError("\(error)")
}
}

// for testing
@discardableResult
internal static func run(configuration: Configuration = .init(), closure: @escaping StringClosure) -> Result<Int, Error> {
self.run(configuration: configuration, handler: StringClosureWrapper(closure))
}

// for testing
@discardableResult
internal static func run(configuration: Configuration = .init(), closure: @escaping StringVoidClosure) -> Result<Int, Error> {
self.run(configuration: configuration, handler: StringVoidClosureWrapper(closure))
}
Expand Down
15 changes: 9 additions & 6 deletions Sources/AWSLambdaRuntimeCore/Lambda.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public enum Lambda {
///
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
public static func run(_ handler: Handler) {
self.run(handler: handler)
if case .failure(let error) = self.run(handler: handler) {
fatalError("\(error)")
}
}

/// Run a Lambda defined by implementing the `LambdaHandler` protocol provided via a `LambdaHandlerFactory`.
Expand All @@ -49,7 +51,9 @@ public enum Lambda {
///
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
public static func run(_ factory: @escaping HandlerFactory) {
self.run(factory: factory)
if case .failure(let error) = self.run(factory: factory) {
fatalError("\(error)")
}
}

/// Run a Lambda defined by implementing the `LambdaHandler` protocol provided via a factory, typically a constructor.
Expand All @@ -59,7 +63,9 @@ public enum Lambda {
///
/// - note: This is a blocking operation that will run forever, as its lifecycle is managed by the AWS Lambda Runtime Engine.
public static func run(_ factory: @escaping (InitializationContext) throws -> Handler) {
self.run(factory: factory)
if case .failure(let error) = self.run(factory: factory) {
fatalError("\(error)")
}
}

/// Utility to access/read environment variables
Expand All @@ -71,13 +77,11 @@ public enum Lambda {
}

// for testing and internal use
@discardableResult
internal static func run(configuration: Configuration = .init(), handler: Handler) -> Result<Int, Error> {
self.run(configuration: configuration, factory: { $0.eventLoop.makeSucceededFuture(handler) })
}

// for testing and internal use
@discardableResult
internal static func run(configuration: Configuration = .init(), factory: @escaping (InitializationContext) throws -> Handler) -> Result<Int, Error> {
self.run(configuration: configuration, factory: { context -> EventLoopFuture<Handler> in
let promise = context.eventLoop.makePromise(of: Handler.self)
Expand All @@ -95,7 +99,6 @@ public enum Lambda {
}

// for testing and internal use
@discardableResult
internal static func run(configuration: Configuration = .init(), factory: @escaping HandlerFactory) -> Result<Int, Error> {
let _run = { (configuration: Configuration, factory: @escaping HandlerFactory) -> Result<Int, Error> in
Backtrace.install()
Expand Down