Skip to content

[AuthBloc] App crashes/throws unhandled exception on HTTP connection errors during user load #332

@jjoonleo

Description

@jjoonleo

Describe the bug
The application fails to gracefully handle HTTP connection errors (specifically DioException) when loading user data. The AuthenticationRemoteDataSourceImpl rethrows network errors, which propagate up through the UserRepository and LoadUserUseCase. The critical issue is in AuthBloc, where _loadUserUseCase() is called but not awaited or wrapped in a try-catch block, resulting in an unhandled exception that can crash the app or pause the debugger.

To Reproduce
Steps to reproduce the behavior:

  1. Set an invalid API URL in the .env file (or disconnect network to force a DNS/Connection error).
  2. Launch the app.
  3. The app attempts to fetch the user profile via AuthBloc.
  4. Observe the DioException (SocketException: Failed host lookup) in the logs/debugger.
  5. The app may crash or enter an undefined state because the error is unhandled in AuthBloc._appUserSubscriptionRequested.

Expected behavior
The application should catch network errors during the initial user load. It should either:

  • Log the error silently and proceed if offline functionality is supported.
  • Emit an error state to the UI to show a friendly message (e.g., "Connection failed").
  • Retry the request gracefully.

Code Reference
In lib/presentation/app/bloc/auth/auth_bloc.dart:

Future<void> _appUserSubscriptionRequested(
  AuthUserSubscriptionRequested event,
  Emitter<AuthState> emit,
) {
  _loadUserUseCase(); // <--- ERROR: Unawaited future with no error handling
  return emit.onEach(
    _streamUserUseCase.call(),
    // ...

Additional context

  • Stack Trace:
    DioException [connection error]: The connection errored: Failed host lookup: 'api.ontime.devkor.club'
    #0      DioMixin.request (package:dio/src/dio_mixin.dart:364:36)
    ...
    #4      LoadUserUseCase.call (package:on_time_front/domain/use-cases/load_user_use_case.dart:11:27)
    #5      AuthBloc._appUserSubscriptionRequested (package:on_time_front/presentation/app/bloc/auth/auth_bloc.dart:34:21)
    
  • Temporary Fix: Updating the API URL in .env resolves the connection error, but the code remains vulnerable to future network failures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions