2727import com .amazonaws .services .lambda .runtime .api .client .logging .LambdaContextLogger ;
2828import com .amazonaws .services .lambda .runtime .api .client .logging .LogSink ;
2929import com .amazonaws .services .lambda .runtime .api .client .logging .StdOutLogSink ;
30+ import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .LambdaError ;
3031import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .LambdaRuntimeApiClient ;
3132import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .LambdaRuntimeApiClientImpl ;
33+ import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .RapidErrorType ;
3234import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .converters .LambdaErrorConverter ;
3335import com .amazonaws .services .lambda .runtime .api .client .runtimeapi .converters .XRayErrorCauseConverter ;
3436import 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 ;
3737import com .amazonaws .services .lambda .runtime .api .client .util .LambdaOutputStream ;
3838import com .amazonaws .services .lambda .runtime .api .client .util .UnsafeUtil ;
3939import com .amazonaws .services .lambda .runtime .logging .LogFormat ;
5454 */
5555public class AWSLambda {
5656
57+ protected static ClassLoader customerClassLoader ;
58+
5759 private static final String TRUST_STORE_PROPERTY = "javax.net.ssl.trustStore" ;
5860
5961 private static final String JAVA_SECURITY_PROPERTIES = "java.security.properties" ;
@@ -75,8 +77,6 @@ public class AWSLambda {
7577 private static final String AWS_LAMBDA_INITIALIZATION_TYPE =
7678 System .getenv (ReservedRuntimeEnvironmentVariables .AWS_LAMBDA_INITIALIZATION_TYPE );
7779
78- protected static ClassLoader customerClassLoader ;
79-
8080 private static LambdaRuntimeApiClient runtimeClient ;
8181
8282 static {
@@ -218,16 +218,13 @@ private static void startRuntime(String handler, LambdaContextLogger lambdaLogge
218218 String taskRoot = System .getProperty ("user.dir" );
219219 String libRoot = "/opt/java" ;
220220 // 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.
227222 //
228223 // customerClassLoader =
229224 // 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.
231228 customerClassLoader = ClassLoader .getSystemClassLoader ();
232229
233230 Thread .currentThread ().setContextClassLoader (customerClassLoader );
@@ -239,7 +236,8 @@ private static void startRuntime(String handler, LambdaContextLogger lambdaLogge
239236 } catch (UserFault userFault ) {
240237 lambdaLogger .log (userFault .reportableError (),
241238 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 );
243241 runtimeClient .reportInitError (error );
244242 System .exit (1 );
245243 return ;
@@ -261,23 +259,23 @@ private static void startRuntime(String handler, LambdaContextLogger lambdaLogge
261259 try {
262260 payload = requestHandler .call (request );
263261 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 ();
266264 } catch (UserFault f ) {
267265 shouldExit = f .fatal ;
268266 userFault = f ;
269267 UserFault .filterStackTrace (f );
270-
271- LambdaError error = LambdaErrorConverter .fromUserFault (f );
268+ LambdaError error =
269+ new LambdaError ( LambdaErrorConverter .fromUserFault (f ), RapidErrorType . BadFunctionCode );
272270 runtimeClient .reportInvocationError (request .getId (), error );
273271 } catch (Throwable t ) {
274272 shouldExit = t instanceof VirtualMachineError || t instanceof IOError ;
275273 UserFault .filterStackTrace (t );
276274 userFault = UserFault .makeUserFault (t );
277275
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 );
281279 } finally {
282280 if (userFault != null ) {
283281 lambdaLogger .log (userFault .reportableError (),
@@ -293,16 +291,16 @@ static void onInitComplete(final LambdaContextLogger lambdaLogger) throws IOExce
293291 runtimeClient .restoreNext ();
294292 } catch (Exception e1 ) {
295293 logExceptionCloudWatch (lambdaLogger , e1 );
296- LambdaError error = LambdaErrorConverter .fromThrowable (e1 );
297- runtimeClient . reportInitError ( error );
294+ runtimeClient . reportInitError ( new LambdaError ( LambdaErrorConverter .fromThrowable (e1 ),
295+ RapidErrorType . BeforeCheckpointError ) );
298296 System .exit (64 );
299297 }
300298 try {
301299 Core .getGlobalContext ().afterRestore (null );
302300 } catch (Exception restoreExc ) {
303301 logExceptionCloudWatch (lambdaLogger , restoreExc );
304- LambdaError error = LambdaErrorConverter . fromThrowable ( restoreExc );
305- runtimeClient . reportRestoreError ( error );
302+ runtimeClient . reportRestoreError ( new LambdaError (
303+ LambdaErrorConverter . fromThrowable ( restoreExc ), RapidErrorType . AfterRestoreError ) );
306304 System .exit (64 );
307305 }
308306 }
0 commit comments