Skip to content

Commit 06a55a1

Browse files
committed
refactor(app): wrap demo user data initialization in try/catch
- Ensures failures in demo data initialization are handled - Prevents potential crashes in demo mode - Adds error logging for failed initialization attempts
1 parent 841e01e commit 06a55a1

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lib/app/bloc/app_bloc.dart

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,23 @@ class AppBloc extends Bloc<AppEvent, AppState> {
127127
// In demo mode, ensure user-specific data is initialized
128128
if (_environment == local_config.AppEnvironment.demo &&
129129
demoDataInitializerService != null) {
130-
print(
131-
'[AppBloc] Demo mode: Initializing user-specific data for '
132-
'user ${event.user!.id}.',
133-
);
134-
await demoDataInitializerService!.initializeUserSpecificData(
135-
event.user!,
136-
);
137-
print(
138-
'[AppBloc] Demo mode: User-specific data initialization completed '
139-
'for user ${event.user!.id}.',
140-
);
130+
try {
131+
print(
132+
'[AppBloc] Demo mode: Initializing user-specific data for '
133+
'user ${event.user!.id}.',
134+
);
135+
await demoDataInitializerService!.initializeUserSpecificData(
136+
event.user!,
137+
);
138+
print(
139+
'[AppBloc] Demo mode: User-specific data initialization completed '
140+
'for user ${event.user!.id}.',
141+
);
142+
} catch (e, s) {
143+
// It's important to handle failures here to avoid crashing the app.
144+
// Consider emitting a specific failure state if this is critical.
145+
print('[AppBloc] ERROR: Failed to initialize demo user data: $e\n$s');
146+
}
141147
}
142148

143149
add(const AppSettingsRefreshed());

0 commit comments

Comments
 (0)