@@ -22,7 +22,7 @@ typedef CodelesslyWidgetLayoutBuilder = Widget Function(
2222/// fails to load.
2323typedef CodelesslyWidgetErrorBuilder = Widget Function (
2424 BuildContext context,
25- dynamic exception ,
25+ ErrorLog error ,
2626);
2727
2828Widget _defaultLayoutBuilder (context, layout) => layout;
@@ -489,21 +489,20 @@ class _CodelesslyWidgetState extends State<CodelesslyWidget> {
489489 final status = _effectiveController.dataManager.status;
490490 try {
491491 if (snapshot.hasError || status is CError ) {
492- final List <ErrorLog > errors = [];
493- if (snapshot.error != null ) {
494- errors.add (ErrorLog (
492+ final ErrorLog error;
493+ if (_lastError != null ) {
494+ error = _lastError! ;
495+ } else {
496+ error = ErrorLog (
495497 timestamp: DateTime .now (),
496- message: snapshot.error.toString (),
498+ message: snapshot.error? .toString () ?? 'Unknown error' ,
497499 type: 'stream_error' ,
498- ));
499- }
500- if (_lastError != null ) {
501- errors.add (_lastError! );
500+ );
502501 }
503502
504- return _effectiveErrorBuilder? .call (context, snapshot. error) ??
503+ return _effectiveErrorBuilder? .call (context, error) ??
505504 CodelesslyErrorScreen (
506- errors: errors ,
505+ errors: [error] ,
507506 publishSource: _effectiveController.publishSource,
508507 );
509508 }
@@ -605,6 +604,13 @@ class _CodelesslyWidgetState extends State<CodelesslyWidget> {
605604 },
606605 );
607606 } catch (e, str) {
607+ final errorLog = ErrorLog (
608+ timestamp: DateTime .now (),
609+ message: e.toString (),
610+ type: 'build_error' ,
611+ stackTrace: str,
612+ );
613+
608614 ErrorLogger .instance.captureException (
609615 e,
610616 message: 'Error building layout' ,
@@ -613,16 +619,9 @@ class _CodelesslyWidgetState extends State<CodelesslyWidget> {
613619 stackTrace: str,
614620 );
615621
616- return _effectiveErrorBuilder? .call (context, e ) ??
622+ return _effectiveErrorBuilder? .call (context, errorLog ) ??
617623 CodelesslyErrorScreen (
618- errors: [
619- ErrorLog (
620- timestamp: DateTime .now (),
621- message: e.toString (),
622- type: 'build_error' ,
623- stackTrace: str,
624- )
625- ],
624+ errors: [errorLog],
626625 publishSource: _effectiveController.publishSource,
627626 );
628627 }
@@ -652,21 +651,20 @@ class _CodelesslyWidgetState extends State<CodelesslyWidget> {
652651 const CodelesslyLoadingScreen ();
653652
654653 Widget error (Object ? error) {
655- final List <ErrorLog > errors = [];
656- if (error != null ) {
657- errors.add (ErrorLog (
654+ final ErrorLog errorLog;
655+ if (_lastError != null ) {
656+ errorLog = _lastError! ;
657+ } else {
658+ errorLog = ErrorLog (
658659 timestamp: DateTime .now (),
659- message: error.toString (),
660+ message: error? .toString () ?? 'Unknown error' ,
660661 type: 'build_error' ,
661- ));
662- }
663- if (_lastError != null ) {
664- errors.add (_lastError! );
662+ );
665663 }
666664
667- return _effectiveErrorBuilder? .call (context, error ) ??
665+ return _effectiveErrorBuilder? .call (context, errorLog ) ??
668666 CodelesslyErrorScreen (
669- errors: errors ,
667+ errors: [errorLog] ,
670668 publishSource: _effectiveController.publishSource,
671669 );
672670 }
0 commit comments