27
27
import com .amazonaws .services .lambda .runtime .api .client .logging .LambdaContextLogger ;
28
28
import com .amazonaws .services .lambda .runtime .api .client .logging .LogSink ;
29
29
import com .amazonaws .services .lambda .runtime .api .client .logging .StdOutLogSink ;
30
+ import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .LambdaError ;
30
31
import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .LambdaRuntimeApiClient ;
31
32
import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .LambdaRuntimeApiClientImpl ;
33
+ import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .RapidErrorType ;
32
34
import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .converters .LambdaErrorConverter ;
33
35
import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .converters .XRayErrorCauseConverter ;
34
36
import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .dto .InvocationRequest ;
35
- import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .dto .LambdaError ;
36
- import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .dto .XRayErrorCause ;
37
37
import com .amazonaws .services .lambda .runtime .api .client .util .LambdaOutputStream ;
38
38
import com .amazonaws .services .lambda .runtime .api .client .util .UnsafeUtil ;
39
39
import com .amazonaws .services .lambda .runtime .logging .LogFormat ;
54
54
*/
55
55
public class AWSLambda {
56
56
57
+ protected static ClassLoader customerClassLoader ;
58
+
57
59
private static final String TRUST_STORE_PROPERTY = "javax.net.ssl.trustStore" ;
58
60
59
61
private static final String JAVA_SECURITY_PROPERTIES = "java.security.properties" ;
@@ -75,8 +77,6 @@ public class AWSLambda {
75
77
private static final String AWS_LAMBDA_INITIALIZATION_TYPE =
76
78
System .getenv (ReservedRuntimeEnvironmentVariables .AWS_LAMBDA_INITIALIZATION_TYPE );
77
79
78
- protected static ClassLoader customerClassLoader ;
79
-
80
80
private static LambdaRuntimeApiClient runtimeClient ;
81
81
82
82
static {
@@ -218,16 +218,13 @@ private static void startRuntime(String handler, LambdaContextLogger lambdaLogge
218
218
String taskRoot = System .getProperty ("user.dir" );
219
219
String libRoot = "/opt/java" ;
220
220
// Make system classloader the customer classloader's parent to ensure any aws-lambda-java-core
221
- // classes
222
- // are loaded from the system classloader.
223
-
224
-
225
- // aboothe 20240620 just use the system class loader. This allows us to load code from the
226
- // ServiceLoader, which we otherwise could not do using the custom class loader.
221
+ // classes are loaded from the system classloader.
227
222
//
228
223
// customerClassLoader =
229
224
// new CustomerClassLoader(taskRoot, libRoot, ClassLoader.getSystemClassLoader());
230
- //
225
+
226
+ // aboothe 20240620 just use the system class loader. This allows us to load code from the
227
+ // ServiceLoader, which we otherwise could not do using the custom class loader.
231
228
customerClassLoader = ClassLoader .getSystemClassLoader ();
232
229
233
230
Thread .currentThread ().setContextClassLoader (customerClassLoader );
@@ -239,7 +236,8 @@ private static void startRuntime(String handler, LambdaContextLogger lambdaLogge
239
236
} catch (UserFault userFault ) {
240
237
lambdaLogger .log (userFault .reportableError (),
241
238
lambdaLogger .getLogFormat () == LogFormat .JSON ? LogLevel .ERROR : LogLevel .UNDEFINED );
242
- LambdaError error = LambdaErrorConverter .fromUserFault (userFault );
239
+ LambdaError error = new LambdaError (LambdaErrorConverter .fromUserFault (userFault ),
240
+ RapidErrorType .BadFunctionCode );
243
241
runtimeClient .reportInitError (error );
244
242
System .exit (1 );
245
243
return ;
@@ -261,23 +259,23 @@ private static void startRuntime(String handler, LambdaContextLogger lambdaLogge
261
259
try {
262
260
payload = requestHandler .call (request );
263
261
runtimeClient .reportInvocationSuccess (request .getId (), payload .toByteArray ());
264
- boolean ignored = Thread . interrupted (); // clear interrupted flag in case if it was set by
265
- // user's code
262
+ // clear interrupted flag in case if it was set by user's code
263
+ boolean ignored = Thread . interrupted ();
266
264
} catch (UserFault f ) {
267
265
shouldExit = f .fatal ;
268
266
userFault = f ;
269
267
UserFault .filterStackTrace (f );
270
-
271
- LambdaError error = LambdaErrorConverter .fromUserFault (f );
268
+ LambdaError error =
269
+ new LambdaError ( LambdaErrorConverter .fromUserFault (f ), RapidErrorType . BadFunctionCode );
272
270
runtimeClient .reportInvocationError (request .getId (), error );
273
271
} catch (Throwable t ) {
274
272
shouldExit = t instanceof VirtualMachineError || t instanceof IOError ;
275
273
UserFault .filterStackTrace (t );
276
274
userFault = UserFault .makeUserFault (t );
277
275
278
- LambdaError error = LambdaErrorConverter .fromThrowable (t );
279
- XRayErrorCause xRayErrorCause = XRayErrorCauseConverter .fromThrowable (t );
280
- runtimeClient .reportInvocationError (request .getId (), error , xRayErrorCause );
276
+ LambdaError error = new LambdaError ( LambdaErrorConverter .fromThrowable (t ),
277
+ XRayErrorCauseConverter .fromThrowable (t ), RapidErrorType . UserException );
278
+ runtimeClient .reportInvocationError (request .getId (), error );
281
279
} finally {
282
280
if (userFault != null ) {
283
281
lambdaLogger .log (userFault .reportableError (),
@@ -293,16 +291,16 @@ static void onInitComplete(final LambdaContextLogger lambdaLogger) throws IOExce
293
291
runtimeClient .restoreNext ();
294
292
} catch (Exception e1 ) {
295
293
logExceptionCloudWatch (lambdaLogger , e1 );
296
- LambdaError error = LambdaErrorConverter .fromThrowable (e1 );
297
- runtimeClient . reportInitError ( error );
294
+ runtimeClient . reportInitError ( new LambdaError ( LambdaErrorConverter .fromThrowable (e1 ),
295
+ RapidErrorType . BeforeCheckpointError ) );
298
296
System .exit (64 );
299
297
}
300
298
try {
301
299
Core .getGlobalContext ().afterRestore (null );
302
300
} catch (Exception restoreExc ) {
303
301
logExceptionCloudWatch (lambdaLogger , restoreExc );
304
- LambdaError error = LambdaErrorConverter . fromThrowable ( restoreExc );
305
- runtimeClient . reportRestoreError ( error );
302
+ runtimeClient . reportRestoreError ( new LambdaError (
303
+ LambdaErrorConverter . fromThrowable ( restoreExc ), RapidErrorType . AfterRestoreError ) );
306
304
System .exit (64 );
307
305
}
308
306
}
0 commit comments