Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dio creates Uncaught Exception in the method that will catch it. #2023

Closed
Nikzed opened this issue Nov 4, 2023 · 4 comments
Closed

Dio creates Uncaught Exception in the method that will catch it. #2023

Nikzed opened this issue Nov 4, 2023 · 4 comments
Labels
i: duplicate This issue or pull request already exists

Comments

@Nikzed
Copy link

Nikzed commented Nov 4, 2023

Package

dio

Version

5.3.3

Operating-System

Android

Output of flutter doctor -v

[!] Flutter (Channel unknown, 3.10.5, on Microsoft Windows [Version 10.0.19045.3570], locale en-US)
    ! Flutter version 3.10.5 on channel unknown at C:\src\flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at
      https://flutter.dev/docs/get-started/install.
    ! Unknown upstream repository.
      Reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    • Framework revision 796c8ef792 (5 months ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly
      to perform update checks and upgrades.

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at C:\Users\NikitaWork\AppData\Local\Android\sdk
    • Platform android-33-ext4, build-tools 33.0.1
    • Java binary at: C:\Program Files\Java\jdk-11.0.17\bin\java
    • Java version Java(TM) SE Runtime Environment 18.9 (build 11.0.17+10-LTS-269)
    • All Android licenses accepted.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[!] Android Studio (version 2022.3)
    • Android Studio at C:\Program Files\Android
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    X Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[√] VS Code (version 1.84.0)
    • VS Code at C:\Users\NikitaWork\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.76.0

[√] Connected device (3 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)       • windows       • windows-x64    • Microsoft Windows [Version 10.0.19045.3570]
    • Edge (web)              • edge          • web-javascript • Microsoft Edge 118.0.2088.76

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 4 categories.

Dart Version

3.0.5

Steps to Reproduce

I created a repository that will return a random color from request. I've added very short amount of time before timeout exception, because I will generate it locally then.

The project is using retrofit.

Dio getDio() {
  Dio dio = Dio();

  dio.options = BaseOptions(
    baseUrl: 'https://solid.free.mockoapp.net/',
    receiveDataWhenStatusError: true,
    connectTimeout: const Duration(seconds: 1),
    receiveTimeout: const Duration(seconds: 1),
  );

  return dio;
}

abstract class RandomRgbRepository {
  Future<Color> getRandomColor();
}

class RandomRgbRepositoryImpl implements RandomRgbRepository {
  final RandomRgbApi _randomRgbApi;
  final RgbColorMapper _rgbColorMapper;

  RandomRgbRepositoryImpl(this._randomRgbApi, this._rgbColorMapper);

  @override
  Future<Color> getRandomColor() async {
    try {
      final RgbResponse response = await _randomRgbApi.getRandomColor();
      return _rgbColorMapper.map(response);
    } on Exception catch (e) {
      throw Exception(e);
    }
  }
}

@RestApi(baseUrl: "https://solid.free.mockoapp.net/")
abstract class RandomRgbApi {
  factory RandomRgbApi(Dio dio, {String baseUrl}) = _RandomRgbApi;

  @GET("/rgb")
  Future<RgbResponse> getRandomColor();
}

@JsonSerializable()
class RgbResponse {
  final int r;
  final int g;
  final int b;

  RgbResponse(this.r, this.g, this.b);

  factory RgbResponse.fromJson(Map<String, dynamic> json) =>
      _$RgbResponseFromJson(json);

  Map<String, dynamic> toJson() => _$RgbResponseToJson(this);
}

class GetRandomColorUseCase {
  final RandomRgbRepository _repository = injector();

  Future<Color> call() async {
    return await _repository.getRandomColor().onError((error, stackTrace) {
      final random = Random();
      return Color.fromRGBO(
        random.nextInt(256),
        random.nextInt(256),
        random.nextInt(256),
        1,
      );
    });
  }
}

Expected Result

I want to not see Uncaught exception when I catch it.

Actual Result

image

io_adapter.dart
Future _fetch(***) method
image

@Nikzed Nikzed added h: need triage This issue needs to be categorized s: bug Something isn't working labels Nov 4, 2023
@Nikzed Nikzed closed this as completed Nov 4, 2023
@Nikzed Nikzed reopened this Nov 4, 2023
@AlexV525
Copy link
Member

AlexV525 commented Nov 5, 2023

Duplicate of #1869

@AlexV525 AlexV525 marked this as a duplicate of #1869 Nov 5, 2023
@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 5, 2023
@AlexV525 AlexV525 added i: duplicate This issue or pull request already exists and removed h: need triage This issue needs to be categorized s: bug Something isn't working labels Nov 5, 2023
@Nikzed
Copy link
Author

Nikzed commented Nov 13, 2023

Duplicate of #1869

it is not duplicate. It was fixed by restarting PC and VS Code. So I don't think this is appropriate to guide people to that thread

@AlexV525
Copy link
Member

it is not duplicate. It was fixed by restarting PC and VS Code.

Which means the exceptions themselves do not occur after another session of running. That doesn't mean the linked thread is resolved, or related to Dio anyway.

@DukePeoPlus
Copy link

@Nikzed
same issue.
Do you know the cause of the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants