@@ -207,7 +207,7 @@ function () use ($debugbar, $startTime) {
207
207
$ this ->app ['config ' ]->get ('debugbar.options.exceptions.chain ' , true )
208
208
);
209
209
$ this ->addCollector ($ exceptionCollector );
210
- } catch (\ Exception $ e ) {
210
+ } catch (Exception $ e ) {
211
211
}
212
212
}
213
213
@@ -224,14 +224,8 @@ function () use ($debugbar, $startTime) {
224
224
$ startTime = $ this ->app ['request ' ]->server ('REQUEST_TIME_FLOAT ' );
225
225
$ this ->addCollector (new EventCollector ($ startTime ));
226
226
$ this ->app ['events ' ]->subscribe ($ debugbar ['event ' ]);
227
- } catch (\Exception $ e ) {
228
- $ this ->addThrowable (
229
- new Exception (
230
- 'Cannot add EventCollector to Laravel Debugbar: ' . $ e ->getMessage (),
231
- $ e ->getCode (),
232
- $ e
233
- )
234
- );
227
+ } catch (Exception $ e ) {
228
+ $ this ->addCollectorException ('Cannot add EventCollector ' , $ e );
235
229
}
236
230
}
237
231
@@ -250,28 +244,16 @@ function ($view, $data = []) use ($debugbar) {
250
244
$ debugbar ['views ' ]->addView ($ view );
251
245
}
252
246
);
253
- } catch (\Exception $ e ) {
254
- $ this ->addThrowable (
255
- new Exception (
256
- 'Cannot add ViewCollector to Laravel Debugbar: ' . $ e ->getMessage (),
257
- $ e ->getCode (),
258
- $ e
259
- )
260
- );
247
+ } catch (Exception $ e ) {
248
+ $ this ->addCollectorException ('Cannot add ViewCollector ' , $ e );
261
249
}
262
250
}
263
251
264
252
if (!$ this ->isLumen () && $ this ->shouldCollect ('route ' )) {
265
253
try {
266
254
$ this ->addCollector ($ this ->app ->make ('Barryvdh\Debugbar\DataCollector\RouteCollector ' ));
267
- } catch (\Exception $ e ) {
268
- $ this ->addThrowable (
269
- new Exception (
270
- 'Cannot add RouteCollector to Laravel Debugbar: ' . $ e ->getMessage (),
271
- $ e ->getCode (),
272
- $ e
273
- )
274
- );
255
+ } catch (Exception $ e ) {
256
+ $ this ->addCollectorException ('Cannot add RouteCollector ' , $ e );
275
257
}
276
258
}
277
259
@@ -298,7 +280,7 @@ function ($level, $message = null, $context = null) use ($logger) {
298
280
} else {
299
281
$ logMessage = "[INVALID UTF-8 DATA] " ;
300
282
}
301
- } catch (\ Exception $ e ) {
283
+ } catch (Exception $ e ) {
302
284
$ logMessage = "[Exception: " . $ e ->getMessage () . "] " ;
303
285
}
304
286
$ logger ->addMessage (
@@ -311,14 +293,8 @@ function ($level, $message = null, $context = null) use ($logger) {
311
293
} else {
312
294
$ this ->addCollector (new MonologCollector ($ this ->getMonologLogger ()));
313
295
}
314
- } catch (\Exception $ e ) {
315
- $ this ->addThrowable (
316
- new Exception (
317
- 'Cannot add LogsCollector to Laravel Debugbar: ' . $ e ->getMessage (),
318
- $ e ->getCode (),
319
- $ e
320
- )
321
- );
296
+ } catch (Exception $ e ) {
297
+ $ this ->addCollectorException ('Cannot add LogsCollector ' , $ e );
322
298
}
323
299
}
324
300
@@ -383,14 +359,8 @@ function (\Illuminate\Database\Events\QueryExecuted $query) {
383
359
}
384
360
}
385
361
);
386
- } catch (\Exception $ e ) {
387
- $ this ->addThrowable (
388
- new Exception (
389
- 'Cannot add listen to Queries for Laravel Debugbar: ' . $ e ->getMessage (),
390
- $ e ->getCode (),
391
- $ e
392
- )
393
- );
362
+ } catch (Exception $ e ) {
363
+ $ this ->addCollectorException ('Cannot listen to Queries ' , $ e );
394
364
}
395
365
396
366
try {
@@ -447,14 +417,8 @@ function (\Illuminate\Database\Events\ConnectionEstablished $event) use ($queryC
447
417
}
448
418
}
449
419
);
450
- } catch (\Exception $ e ) {
451
- $ this ->addThrowable (
452
- new Exception (
453
- 'Cannot add listen transactions to Queries for Laravel Debugbar: ' . $ e ->getMessage (),
454
- $ e ->getCode (),
455
- $ e
456
- )
457
- );
420
+ } catch (Exception $ e ) {
421
+ $ this ->addCollectorException ('Cannot listen transactions to Queries ' , $ e );
458
422
}
459
423
}
460
424
@@ -466,19 +430,17 @@ function (\Illuminate\Database\Events\ConnectionEstablished $event) use ($queryC
466
430
$ this ['models ' ]->countClass ($ model );
467
431
}
468
432
});
469
- } catch (\ Exception $ e ) {
470
- // No Models collector
433
+ } catch (Exception $ e ) {
434
+ $ this -> addCollectorException ( ' Cannot add Models Collector ' , $ e );
471
435
}
472
436
}
473
437
474
438
if ($ this ->shouldCollect ('livewire ' , true ) && $ this ->app ->bound ('livewire ' )) {
475
439
try {
476
440
$ livewireCollector = $ this ->app ->make ('Barryvdh\Debugbar\DataCollector\LivewireCollector ' );
477
441
$ this ->addCollector ($ livewireCollector );
478
- } catch (\Exception $ e ) {
479
- $ this ->addThrowable (
480
- new Exception ('Cannot add Livewire Collector: ' . $ e ->getMessage (), $ e ->getCode (), $ e )
481
- );
442
+ } catch (Exception $ e ) {
443
+ $ this ->addCollectorException ('Cannot add Livewire Collector ' , $ e );
482
444
}
483
445
}
484
446
@@ -524,29 +486,17 @@ public function __toString(): string
524
486
}
525
487
});
526
488
}
527
- } catch (\Exception $ e ) {
528
- $ this ->addThrowable (
529
- new Exception (
530
- 'Cannot add MailCollector to Laravel Debugbar: ' . $ e ->getMessage (),
531
- $ e ->getCode (),
532
- $ e
533
- )
534
- );
489
+ } catch (Exception $ e ) {
490
+ $ this ->addCollectorException ('Cannot add SymfonyMailCollector ' , $ e );
535
491
}
536
492
}
537
493
538
494
if ($ this ->shouldCollect ('logs ' , false )) {
539
495
try {
540
496
$ file = $ this ->app ['config ' ]->get ('debugbar.options.logs.file ' );
541
497
$ this ->addCollector (new LogsCollector ($ file ));
542
- } catch (\Exception $ e ) {
543
- $ this ->addThrowable (
544
- new Exception (
545
- 'Cannot add LogsCollector to Laravel Debugbar: ' . $ e ->getMessage (),
546
- $ e ->getCode (),
547
- $ e
548
- )
549
- );
498
+ } catch (Exception $ e ) {
499
+ $ this ->addCollectorException ('Cannot add LogsCollector ' , $ e );
550
500
}
551
501
}
552
502
if ($ this ->shouldCollect ('files ' , false )) {
@@ -562,23 +512,17 @@ public function __toString(): string
562
512
$ this ->app ['config ' ]->get ('debugbar.options.auth.show_name ' )
563
513
);
564
514
$ this ->addCollector ($ authCollector );
565
- } catch (\Exception $ e ) {
566
- $ this ->addThrowable (
567
- new Exception (
568
- 'Cannot add AuthCollector to Laravel Debugbar: ' . $ e ->getMessage (),
569
- $ e ->getCode (),
570
- $ e
571
- )
572
- );
515
+ } catch (Exception $ e ) {
516
+ $ this ->addCollectorException ('Cannot add AuthCollector ' , $ e );
573
517
}
574
518
}
575
519
576
520
if ($ this ->shouldCollect ('gate ' , false )) {
577
521
try {
578
522
$ gateCollector = $ this ->app ->make ('Barryvdh\Debugbar\DataCollector\GateCollector ' );
579
523
$ this ->addCollector ($ gateCollector );
580
- } catch (\ Exception $ e ) {
581
- // No Gate collector
524
+ } catch (Exception $ e ) {
525
+ $ this -> addCollectorException ( ' Cannot add GateCollector ' , $ e );
582
526
}
583
527
}
584
528
@@ -589,14 +533,8 @@ public function __toString(): string
589
533
$ cacheCollector = new CacheCollector ($ startTime , $ collectValues );
590
534
$ this ->addCollector ($ cacheCollector );
591
535
$ this ->app ['events ' ]->subscribe ($ cacheCollector );
592
- } catch (\Exception $ e ) {
593
- $ this ->addThrowable (
594
- new Exception (
595
- 'Cannot add CacheCollector to Laravel Debugbar: ' . $ e ->getMessage (),
596
- $ e ->getCode (),
597
- $ e
598
- )
599
- );
536
+ } catch (Exception $ e ) {
537
+ $ this ->addCollectorException ('Cannot add CacheCollector ' , $ e );
600
538
}
601
539
}
602
540
@@ -606,8 +544,8 @@ public function __toString(): string
606
544
$ this ->app ['events ' ]->listen (\Illuminate \Queue \Events \JobQueued::class, function ($ event ) {
607
545
$ this ['jobs ' ]->countClass ($ event ->job );
608
546
});
609
- } catch (\ Exception $ e ) {
610
- // No Jobs collector
547
+ } catch (Exception $ e ) {
548
+ $ this -> addCollectorException ( ' Cannot add Jobs Collector ' , $ e );
611
549
}
612
550
}
613
551
@@ -696,7 +634,7 @@ public function stopMeasure($name)
696
634
$ collector = $ this ->getCollector ('time ' );
697
635
try {
698
636
$ collector ->stopMeasure ($ name );
699
- } catch (\ Exception $ e ) {
637
+ } catch (Exception $ e ) {
700
638
// $this->addThrowable($e);
701
639
}
702
640
}
@@ -727,6 +665,23 @@ public function addThrowable($e)
727
665
}
728
666
}
729
667
668
+ /**
669
+ * Register collector exceptions
670
+ *
671
+ * @param string $message
672
+ * @param Exception $exception
673
+ */
674
+ protected function addCollectorException (string $ message , Exception $ exception )
675
+ {
676
+ $ this ->addThrowable (
677
+ new Exception (
678
+ $ message . ' on Laravel Debugbar: ' . $ exception ->getMessage (),
679
+ $ exception ->getCode (),
680
+ $ exception
681
+ )
682
+ );
683
+ }
684
+
730
685
/**
731
686
* Returns a JavascriptRenderer for this instance
732
687
*
@@ -766,14 +721,8 @@ public function modifyResponse(Request $request, Response $response)
766
721
$ configCollector = new ConfigCollector ();
767
722
$ configCollector ->setData ($ app ['config ' ]->all ());
768
723
$ this ->addCollector ($ configCollector );
769
- } catch (\Exception $ e ) {
770
- $ this ->addThrowable (
771
- new Exception (
772
- 'Cannot add ConfigCollector to Laravel Debugbar: ' . $ e ->getMessage (),
773
- $ e ->getCode (),
774
- $ e
775
- )
776
- );
724
+ } catch (Exception $ e ) {
725
+ $ this ->addCollectorException ('Cannot add ConfigCollector ' , $ e );
777
726
}
778
727
}
779
728
@@ -788,14 +737,8 @@ public function modifyResponse(Request $request, Response $response)
788
737
if ($ this ->shouldCollect ('session ' ) && ! $ this ->hasCollector ('session ' )) {
789
738
try {
790
739
$ this ->addCollector (new SessionCollector ($ sessionManager , $ sessionHiddens ));
791
- } catch (\Exception $ e ) {
792
- $ this ->addThrowable (
793
- new Exception (
794
- 'Cannot add SessionCollector to Laravel Debugbar: ' . $ e ->getMessage (),
795
- $ e ->getCode (),
796
- $ e
797
- )
798
- );
740
+ } catch (Exception $ e ) {
741
+ $ this ->addCollectorException ('Cannot add SessionCollector ' , $ e );
799
742
}
800
743
}
801
744
} else {
@@ -810,28 +753,16 @@ public function modifyResponse(Request $request, Response $response)
810
753
try {
811
754
$ reqId = $ this ->getCurrentRequestId ();
812
755
$ this ->addCollector (new RequestCollector ($ request , $ response , $ sessionManager , $ reqId , $ requestHiddens ));
813
- } catch (\Exception $ e ) {
814
- $ this ->addThrowable (
815
- new Exception (
816
- 'Cannot add SymfonyRequestCollector to Laravel Debugbar: ' . $ e ->getMessage (),
817
- $ e ->getCode (),
818
- $ e
819
- )
820
- );
756
+ } catch (Exception $ e ) {
757
+ $ this ->addCollectorException ('Cannot add SymfonyRequestCollector ' , $ e );
821
758
}
822
759
}
823
760
824
761
if ($ app ['config ' ]->get ('debugbar.clockwork ' ) && ! $ this ->hasCollector ('clockwork ' )) {
825
762
try {
826
763
$ this ->addCollector (new ClockworkCollector ($ request , $ response , $ sessionManager , $ requestHiddens ));
827
- } catch (\Exception $ e ) {
828
- $ this ->addThrowable (
829
- new Exception (
830
- 'Cannot add ClockworkCollector to Laravel Debugbar: ' . $ e ->getMessage (),
831
- $ e ->getCode (),
832
- $ e
833
- )
834
- );
764
+ } catch (Exception $ e ) {
765
+ $ this ->addCollectorException ('Cannot add ClockworkCollector ' , $ e );
835
766
}
836
767
837
768
$ this ->addClockworkHeaders ($ response );
@@ -840,7 +771,7 @@ public function modifyResponse(Request $request, Response $response)
840
771
if ($ response ->isRedirection ()) {
841
772
try {
842
773
$ this ->stackData ();
843
- } catch (\ Exception $ e ) {
774
+ } catch (Exception $ e ) {
844
775
$ app ['log ' ]->error ('Debugbar exception: ' . $ e ->getMessage ());
845
776
}
846
777
} elseif (
@@ -853,7 +784,7 @@ public function modifyResponse(Request $request, Response $response)
853
784
if ($ app ['config ' ]->get ('debugbar.add_ajax_timing ' , false )) {
854
785
$ this ->addServerTimingHeaders ($ response );
855
786
}
856
- } catch (\ Exception $ e ) {
787
+ } catch (Exception $ e ) {
857
788
$ app ['log ' ]->error ('Debugbar exception: ' . $ e ->getMessage ());
858
789
}
859
790
} elseif (
@@ -867,13 +798,13 @@ public function modifyResponse(Request $request, Response $response)
867
798
try {
868
799
// Just collect + store data, don't inject it.
869
800
$ this ->collect ();
870
- } catch (\ Exception $ e ) {
801
+ } catch (Exception $ e ) {
871
802
$ app ['log ' ]->error ('Debugbar exception: ' . $ e ->getMessage ());
872
803
}
873
804
} else {
874
805
try {
875
806
$ this ->injectDebugbar ($ response );
876
- } catch (\ Exception $ e ) {
807
+ } catch (Exception $ e ) {
877
808
$ app ['log ' ]->error ('Debugbar exception: ' . $ e ->getMessage ());
878
809
}
879
810
}
0 commit comments