@@ -59,20 +59,7 @@ public final class LambdaRuntime<Handler>: Sendable where Handler: StreamingLamb
59
59
#if !ServiceLifecycleSupport
60
60
@inlinable
61
61
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 ( )
76
63
}
77
64
#endif
78
65
@@ -107,6 +94,7 @@ public final class LambdaRuntime<Handler>: Sendable where Handler: StreamingLamb
107
94
let ip = String ( ipAndPort [ 0 ] )
108
95
guard let port = Int ( ipAndPort [ 1 ] ) else { throw LambdaRuntimeError ( code: . invalidPort) }
109
96
97
+ do {
110
98
try await LambdaRuntimeClient . withRuntimeClient (
111
99
configuration: . init( ip: ip, port: port) ,
112
100
eventLoop: self . eventLoop,
@@ -118,6 +106,18 @@ public final class LambdaRuntime<Handler>: Sendable where Handler: StreamingLamb
118
106
logger: self . logger
119
107
)
120
108
}
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
+ }
121
121
122
122
} else {
123
123
0 commit comments