Skip to content

Commit dc50cd8

Browse files
committed
Migrate ErrorLogger #2
- Migrate ErrorBuilder.
1 parent 7c195a5 commit dc50cd8

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

lib/src/transformers/node_transformers/passive_grid_view_transformer.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
77
import 'package:provider/provider.dart';
88

99
import '../../../codelessly_sdk.dart';
10+
import '../../logging/error_logger.dart';
1011
import '../../ui/draggable_scroll_configuration.dart';
1112

1213
class PassiveGridViewTransformer extends NodeWidgetTransformer<GridViewNode> {
@@ -88,7 +89,11 @@ class PassiveGridViewWidget extends StatelessWidget {
8889
if (snapshot.hasError) {
8990
return codelesslyController.errorBuilder?.call(
9091
context,
91-
snapshot.error,
92+
ErrorLog(
93+
timestamp: DateTime.now(),
94+
message: snapshot.error?.toString() ?? 'Unknown error',
95+
type: 'firestore_query_error',
96+
),
9297
) ??
9398
const Center(child: Text('Error'));
9499
}

lib/src/transformers/node_transformers/passive_list_view_transformer.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
77
import 'package:provider/provider.dart';
88

99
import '../../../codelessly_sdk.dart';
10+
import '../../logging/error_logger.dart';
1011
import '../../ui/draggable_scroll_configuration.dart';
1112

1213
class PassiveListViewTransformer extends NodeWidgetTransformer<ListViewNode> {
@@ -89,7 +90,11 @@ class PassiveListViewWidget extends StatelessWidget {
8990
if (snapshot.hasError) {
9091
return codelesslyController.errorBuilder?.call(
9192
context,
92-
snapshot.error,
93+
ErrorLog(
94+
timestamp: DateTime.now(),
95+
message: snapshot.error?.toString() ?? 'Unknown error',
96+
type: 'firestore_query_error',
97+
),
9398
) ??
9499
const Center(child: Text('Error'));
95100
}

lib/src/ui/codelessly_widget.dart

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ typedef CodelesslyWidgetLayoutBuilder = Widget Function(
2222
/// fails to load.
2323
typedef CodelesslyWidgetErrorBuilder = Widget Function(
2424
BuildContext context,
25-
dynamic exception,
25+
ErrorLog error,
2626
);
2727

2828
Widget _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

Comments
 (0)