13
13
use Illuminate \Contracts \Support \Responsable ;
14
14
use Illuminate \Support \Arr ;
15
15
use Illuminate \Support \Str ;
16
+ use Throwable ;
16
17
17
18
class SettledResult implements Responsable, ResultContract
18
19
{
@@ -211,29 +212,33 @@ protected function parseLogs()
211
212
$ lines = explode ("\n" , $ lines );
212
213
213
214
$ lines = array_map (function ($ line ) use (&$ reportLineReached ) {
214
- if ($ reportLineReached ) {
215
- return null ;
216
- }
215
+ try {
216
+ if ($ reportLineReached ) {
217
+ return null ;
218
+ }
217
219
218
- if (Str::startsWith ($ line , 'START RequestId: ' )) {
219
- return $ this ->parseStartLine ($ line );
220
- }
220
+ if (Str::startsWith ($ line , 'START RequestId: ' )) {
221
+ return $ this ->parseStartLine ($ line );
222
+ }
221
223
222
- if (Str::startsWith ($ line , 'END RequestId: ' )) {
223
- return null ;
224
- }
224
+ if (Str::startsWith ($ line , 'END RequestId: ' )) {
225
+ return null ;
226
+ }
225
227
226
- if (Str::startsWith ($ line , 'REPORT RequestId ' )) {
227
- $ reportLineReached = true ;
228
+ if (Str::startsWith ($ line , 'REPORT RequestId ' )) {
229
+ $ reportLineReached = true ;
228
230
229
- return $ this ->parseReportLine ($ line );
230
- }
231
+ return $ this ->parseReportLine ($ line );
232
+ }
231
233
232
- if ($ line === '' ) {
233
- return null ;
234
- }
234
+ if ($ line === '' ) {
235
+ return null ;
236
+ }
235
237
236
- return $ this ->parseInfoLine ($ line );
238
+ return $ this ->parseInfoLine ($ line );
239
+ } catch (Throwable $ exception ) {
240
+ return $ this ->unknownLine ($ line );
241
+ }
237
242
}, $ lines );
238
243
239
244
return array_values (array_filter ($ lines ));
@@ -251,12 +256,8 @@ protected function parseInfoLine($line)
251
256
{
252
257
$ parts = explode ("\t" , $ line );
253
258
254
- if (count ($ parts ) === 1 ) {
255
- return [
256
- 'timestamp ' => now ()->timestamp ,
257
- 'level ' => 'UNKNOWN ' ,
258
- 'body ' => $ parts [0 ]
259
- ];
259
+ if (count ($ parts ) < 4 ) {
260
+ return $ this ->unknownLine ($ line );
260
261
}
261
262
262
263
$ body = $ parts [3 ];
@@ -272,6 +273,15 @@ protected function parseInfoLine($line)
272
273
];
273
274
}
274
275
276
+ protected function unknownLine ($ line )
277
+ {
278
+ return [
279
+ 'timestamp ' => now ()->timestamp ,
280
+ 'level ' => 'UNKNOWN ' ,
281
+ 'body ' => $ line ,
282
+ ];
283
+ }
284
+
275
285
protected function parseReportLine ($ line )
276
286
{
277
287
$ parts = array_filter (explode ("\t" , $ line ));
0 commit comments