@@ -49,50 +49,31 @@ private static function endpoint($environment, $path) {
49
49
return $ c ;
50
50
}
51
51
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
-
72
52
/**
73
53
* Marshals an error according to the AWS specification.
74
54
*
75
55
* @param Throwable $e
76
- * @return string
56
+ * @return [:var]
77
57
*/
78
- private static function error ($ e ) {
58
+ public static function error ($ e ) {
79
59
$ error = ['errorMessage ' => $ e ->getMessage (), 'errorType ' => nameof ($ e ), 'stackTrace ' => []];
80
60
81
61
$ t = XPException::wrap ($ e );
82
62
do {
63
+ $ error ['stackTrace ' ][]= $ t ->compoundMessage ();
83
64
foreach ($ t ->getStackTrace () as $ e ) {
84
65
$ error ['stackTrace ' ][]= sprintf (
85
66
'%s::%s(...) (line %d of %s)%s ' ,
86
67
strtr ($ e ->class , '\\' , '. ' ) ?: '<main> ' ,
87
68
$ e ->method ,
88
69
$ e ->line ,
89
- basename ($ e ->file ),
70
+ $ e -> file ? basename ($ e ->file ) : '' ,
90
71
$ e ->message ? ' - ' .$ e ->message : ''
91
72
);
92
73
}
93
74
} while ($ t = $ t ->getCause ());
94
75
95
- return Json:: of ( $ error) ;
76
+ return $ error ;
96
77
}
97
78
98
79
/**
@@ -109,7 +90,7 @@ public static function main($args) {
109
90
$ lambda = self ::handler ($ environment , Console::$ out )->lambda ();
110
91
} catch (Throwable $ t ) {
111
92
self ::endpoint ($ environment , 'init/error ' )->post (
112
- new RequestData (self ::error ($ t )),
93
+ new RequestData (Json:: of ( self ::error ($ t) )),
113
94
['Content-Type ' => 'application/json ' ]
114
95
);
115
96
return 1 ;
@@ -126,17 +107,16 @@ public static function main($args) {
126
107
127
108
$ context = new Context ($ r ->headers (), $ environment );
128
109
try {
129
- $ event = 0 === $ context ->payloadLength ? null : self ::read ($ r ->in ());
130
-
110
+ $ event = 0 === $ context ->payloadLength ? null : Json::read (new StreamInput ($ r ->in ()));
131
111
$ type = 'response ' ;
132
- $ response = self :: value ( $ lambda ($ event , $ context) );
112
+ $ response = $ lambda ($ event , $ context );
133
113
} catch (Throwable $ t ) {
134
114
$ type = 'error ' ;
135
115
$ response = self ::error ($ t );
136
116
}
137
117
138
118
self ::endpoint ($ environment , "invocation/ {$ context ->awsRequestId }/ {$ type }" )->post (
139
- new RequestData ($ response ),
119
+ new RequestData (Json:: of ( $ response) ),
140
120
['Content-Type ' => 'application/json ' ]
141
121
);
142
122
} while (true );
0 commit comments