@@ -330,4 +330,78 @@ struct LambdaRuntimeClientTests {
330330            } 
331331        } 
332332    } 
333+ 
334+     @Test (  
335+         " reportError() sends the correct errorType for different Error types "  
336+     )  
337+     @available ( LambdaSwift 2 . 0 ,  * )  
338+     func  testReportErrorReturnsProperErrorType( )  async  throws  { 
339+         // Custom error types for testing
340+         struct  MyCustomError :  Error  { 
341+             let  message :  String 
342+         } 
343+ 
344+         enum  MyEnumError :  Error  { 
345+             case  anotherCase( String ) 
346+         } 
347+ 
348+         struct  ErrorReportingBehavior :  LambdaServerBehavior  { 
349+             let  requestId =  UUID ( ) . uuidString
350+             let  event =  " error-testing " 
351+             let  expectedErrorType :  String 
352+ 
353+             func  getInvocation( )  ->  GetInvocationResult  { 
354+                 . success( ( self . requestId,  self . event) ) 
355+             } 
356+ 
357+             func  processResponse( requestId:  String ,  response:  String ? )  ->  Result < String ? ,  ProcessResponseError >  { 
358+                 Issue . record ( " should not process response, expecting error report " ) 
359+                 return  . failure( . internalServerError) 
360+             } 
361+ 
362+             func  processError( requestId:  String ,  error:  ErrorResponse )  ->  Result < Void ,  ProcessErrorError >  { 
363+                 #expect( self . requestId ==  requestId) 
364+                 #expect( 
365+                     error. errorType ==  self . expectedErrorType, 
366+                     " Expected errorType ' \( self . expectedErrorType) ' but got ' \( error. errorType) ' " 
367+                 ) 
368+                 return  . success( ( ) ) 
369+             } 
370+ 
371+             func  processInitError( error:  ErrorResponse )  ->  Result < Void ,  ProcessErrorError >  { 
372+                 Issue . record ( " should not report init error " ) 
373+                 return  . failure( . internalServerError) 
374+             } 
375+         } 
376+ 
377+         // Test with MyCustomError
378+         try await  withMockServer ( behaviour:  ErrorReportingBehavior ( expectedErrorType:  " MyCustomError " ) )  {  port in 
379+             let  configuration  =  LambdaRuntimeClient . Configuration ( ip:  " 127.0.0.1 " ,  port:  port) 
380+ 
381+             try await  LambdaRuntimeClient . withRuntimeClient ( 
382+                 configuration:  configuration, 
383+                 eventLoop:  NIOSingletons . posixEventLoopGroup. next ( ) , 
384+                 logger:  self . logger
385+             )  {  runtimeClient in 
386+                 let  ( _,  writer)  =  try await  runtimeClient. nextInvocation ( ) 
387+                 let  error  =  MyCustomError ( message:  " Something went wrong " ) 
388+                 try await  writer. reportError ( error) 
389+             } 
390+         } 
391+ 
392+         // Test with MyEnumError
393+         try await  withMockServer ( behaviour:  ErrorReportingBehavior ( expectedErrorType:  " MyEnumError " ) )  {  port in 
394+             let  configuration  =  LambdaRuntimeClient . Configuration ( ip:  " 127.0.0.1 " ,  port:  port) 
395+ 
396+             try await  LambdaRuntimeClient . withRuntimeClient ( 
397+                 configuration:  configuration, 
398+                 eventLoop:  NIOSingletons . posixEventLoopGroup. next ( ) , 
399+                 logger:  self . logger
400+             )  {  runtimeClient in 
401+                 let  ( _,  writer)  =  try await  runtimeClient. nextInvocation ( ) 
402+                 let  error  =  MyEnumError . anotherCase ( " test " ) 
403+                 try await  writer. reportError ( error) 
404+             } 
405+         } 
406+     } 
333407} 
0 commit comments