@@ -49,50 +49,31 @@ private static function endpoint($environment, $path) {
4949 return $ c ;
5050 }
5151
52- /**
53- * Reads a value from the given input stream
54- *
55- * @param io.streams.InputStream
56- * @return var
57- */
58- private static function read ($ in ) {
59- return Json::read (new StreamInput ($ in ));
60- }
61-
62- /**
63- * Marshals a value
64- *
65- * @param var $value
66- * @return string
67- */
68- private static function value ($ value ) {
69- return Json::of ($ value );
70- }
71-
7252 /**
7353 * Marshals an error according to the AWS specification.
7454 *
7555 * @param Throwable $e
76- * @return string
56+ * @return [:var]
7757 */
78- private static function error ($ e ) {
58+ public static function error ($ e ) {
7959 $ error = ['errorMessage ' => $ e ->getMessage (), 'errorType ' => nameof ($ e ), 'stackTrace ' => []];
8060
8161 $ t = XPException::wrap ($ e );
8262 do {
63+ $ error ['stackTrace ' ][]= $ t ->compoundMessage ();
8364 foreach ($ t ->getStackTrace () as $ e ) {
8465 $ error ['stackTrace ' ][]= sprintf (
8566 '%s::%s(...) (line %d of %s)%s ' ,
8667 strtr ($ e ->class , '\\' , '. ' ) ?: '<main> ' ,
8768 $ e ->method ,
8869 $ e ->line ,
89- basename ($ e ->file ),
70+ $ e -> file ? basename ($ e ->file ) : '' ,
9071 $ e ->message ? ' - ' .$ e ->message : ''
9172 );
9273 }
9374 } while ($ t = $ t ->getCause ());
9475
95- return Json:: of ( $ error) ;
76+ return $ error ;
9677 }
9778
9879 /**
@@ -109,7 +90,7 @@ public static function main($args) {
10990 $ lambda = self ::handler ($ environment , Console::$ out )->lambda ();
11091 } catch (Throwable $ t ) {
11192 self ::endpoint ($ environment , 'init/error ' )->post (
112- new RequestData (self ::error ($ t )),
93+ new RequestData (Json:: of ( self ::error ($ t) )),
11394 ['Content-Type ' => 'application/json ' ]
11495 );
11596 return 1 ;
@@ -126,17 +107,16 @@ public static function main($args) {
126107
127108 $ context = new Context ($ r ->headers (), $ environment );
128109 try {
129- $ event = 0 === $ context ->payloadLength ? null : self ::read ($ r ->in ());
130-
110+ $ event = 0 === $ context ->payloadLength ? null : Json::read (new StreamInput ($ r ->in ()));
131111 $ type = 'response ' ;
132- $ response = self :: value ( $ lambda ($ event , $ context) );
112+ $ response = $ lambda ($ event , $ context );
133113 } catch (Throwable $ t ) {
134114 $ type = 'error ' ;
135115 $ response = self ::error ($ t );
136116 }
137117
138118 self ::endpoint ($ environment , "invocation/ {$ context ->awsRequestId }/ {$ type }" )->post (
139- new RequestData ($ response ),
119+ new RequestData (Json:: of ( $ response) ),
140120 ['Content-Type ' => 'application/json ' ]
141121 );
142122 } while (true );
0 commit comments