@@ -59,20 +59,7 @@ public final class LambdaRuntime<Handler>: Sendable where Handler: StreamingLamb
5959 #if !ServiceLifecycleSupport
6060 @inlinable
6161 internal func run( ) async throws {
62- do {
63- try await _run ( )
64- } catch {
65- // catch top level errors that have not been handled until now
66- // this avoids the runtime to crash and generate a backtrace
67- self . logger. error ( " LambdaRuntime.run() failed with error " , metadata: [ " error " : " \( error) " ] )
68- if let error = error as? LambdaRuntimeError ,
69- error. code != . connectionToControlPlaneLost
70- {
71- // if the error is a LambdaRuntimeError but not a connection error,
72- // we rethrow it to preserve existing behaviour
73- throw error
74- }
75- }
62+ try await _run ( )
7663 }
7764 #endif
7865
@@ -107,6 +94,7 @@ public final class LambdaRuntime<Handler>: Sendable where Handler: StreamingLamb
10794 let ip = String ( ipAndPort [ 0 ] )
10895 guard let port = Int ( ipAndPort [ 1 ] ) else { throw LambdaRuntimeError ( code: . invalidPort) }
10996
97+ do {
11098 try await LambdaRuntimeClient . withRuntimeClient (
11199 configuration: . init( ip: ip, port: port) ,
112100 eventLoop: self . eventLoop,
@@ -118,6 +106,18 @@ public final class LambdaRuntime<Handler>: Sendable where Handler: StreamingLamb
118106 logger: self . logger
119107 )
120108 }
109+ } catch {
110+ // catch top level errors that have not been handled until now
111+ // this avoids the runtime to crash and generate a backtrace
112+ self . logger. error ( " LambdaRuntime.run() failed with error " , metadata: [ " error " : " \( error) " ] )
113+ if let error = error as? LambdaRuntimeError ,
114+ error. code != . connectionToControlPlaneLost
115+ {
116+ // if the error is a LambdaRuntimeError but not a connection error,
117+ // we rethrow it to preserve existing behaviour
118+ throw error
119+ }
120+ }
121121
122122 } else {
123123
0 commit comments