Catch uncaught async errors and surface response-shape failures

Wrap main in runZonedGuarded and install FlutterError.onError /
PlatformDispatcher.onError so background async failures get logged
instead of dying silently. Guard PrefUtil.init so a SharedPreferences
platform error no longer aborts startup. Recognize TypeError and
FormatException in dioErrorToUserMessage to give a clearer message
when the backend returns an unexpected JSON shape or bad timestamp.
Wrap Settings._save in try/catch so prefs write failures show a
snackbar instead of leaving the Save button silently dead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-05-31 18:55:35 -04:00
co-authored by Claude Sonnet 4.6
parent e70676a193
commit 140ebab035
3 changed files with 55 additions and 18 deletions
+4
View File
@@ -59,6 +59,10 @@ LogInterceptor _buildLogInterceptor() => LogInterceptor(
);
String dioErrorToUserMessage(Object error) {
if (error is TypeError || error is FormatException) {
debugPrint('Backend response shape error: $error');
return 'Unexpected response shape from backend.';
}
if (error is! DioException) {
debugPrint('Non-Dio error from backend call: $error');
return 'Unexpected error.';