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

A request with an interceptor, which produces an error, makes the code stuck. #2138

Open
yehorh opened this issue Mar 13, 2024 · 8 comments · Fixed by #2139
Open

A request with an interceptor, which produces an error, makes the code stuck. #2138

yehorh opened this issue Mar 13, 2024 · 8 comments · Fixed by #2139
Labels
p: dio Targeting `dio` package s: bug Something isn't working

Comments

@yehorh
Copy link

yehorh commented Mar 13, 2024

Package

dio

Version

5.4.1

Operating-System

Android

Output of flutter doctor -v

flutter doctor -v
[✓] Flutter (Channel stable, 3.19.3, on macOS 14.4 23E214 darwin-arm64, locale en-UA)
    • Flutter version 3.19.3 on channel stable at /Users/yehorh/opt/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ba39319843 (6 days ago), 2024-03-07 15:22:21 -0600
    • Engine revision 2e4ba9c6fb
    • Dart version 3.3.1
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc1)
    • Android SDK at /Users/yehorh/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0-rc1
    • Java binary at: /Users/yehorh/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • Android Studio at /Users/yehorh/Applications/Android Studio.app/Contents
    • 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
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.5)
    • IntelliJ at /Users/yehorh/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 78.3.1
    • Dart plugin version 233.14888

[✓] VS Code (version 1.87.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.84.0

[✓] Connected device (4 available)            
    • sdk gphone64 arm64 (mobile) • emulator-5554             • android-arm64  • Android 13 (API 33) (emulator)
    • yiPhone (mobile)            • 00008101-000E28880AD2001E • ios            • iOS 17.4 21E219
    • macOS (desktop)             • macos                     • darwin-arm64   • macOS 14.4 23E214 darwin-arm64
    • Chrome (web)                • chrome                    • web-javascript • Google Chrome 122.0.6261.128

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

• No issues found!

Dart Version

3.3.1

Steps to Reproduce

Here is a minimal example; I can't understand why the error isn't caught in any way, and everything that follows the request never executes.

tried on Android and macOS

import 'package:dio/dio.dart';

Future<void> main() async {
  final dio = Dio();

  dio.interceptors.add(InterceptorWithError());

  try {
    final response = await dio.get('https://google.com');
  } catch (e, st) {
    print('Unreachable code');
  }

  print('Unreachable code too');
}

class InterceptorWithError extends Interceptor {
  @override
  Future<void> onRequest(
    RequestOptions options,
    RequestInterceptorHandler handler,
  ) async {
    throw Exception('some error');
    return handler.next(options);
  }

  @override
  Future<void> onResponse(
    Response response,
    ResponseInterceptorHandler handler,
  ) async {
    handler.next(response);
  }

  @override
  Future<void> onError(
    DioException err,
    ErrorInterceptorHandler handler,
  ) async {
    handler.next(err);
  }
}

Expected Result

Errors from broken requests must be caught.

Actual Result

The program stops when executing a request, and the subsequent code becomes unreachable.

@yehorh yehorh added h: need triage This issue needs to be categorized s: bug Something isn't working labels Mar 13, 2024
@AlexV525 AlexV525 added p: dio Targeting `dio` package and removed h: need triage This issue needs to be categorized labels Mar 14, 2024
@yehorh
Copy link
Author

yehorh commented Mar 14, 2024

It seems I have broken the interface contract.
I have overridden synchronous functions with asynchronous functions.

The override_on_non_overriding_member lint hasn't helped me this time.

@yehorh yehorh closed this as completed Mar 14, 2024
github-merge-queue bot pushed a commit that referenced this issue Mar 15, 2024
Resolves #2138

### New Pull Request Checklist

- [x] I have read the
[Documentation](https://pub.dev/documentation/dio/latest/)
- [x] I have searched for a similar pull request in the
[project](https://github.com/cfug/dio/pulls) and found none
- [x] I have updated this branch with the latest `main` branch to avoid
conflicts (via merge from master or rebase)
- [x] I have added the required tests to prove the fix/feature I'm
adding
- [ ] I have updated the documentation (if necessary)
- [x] I have run the tests without failures
- [x] I have updated the `CHANGELOG.md` in the corresponding package

---------

Signed-off-by: CaiJingLong <cjl_spy@163.com>
Co-authored-by: Alex Li <github@alexv525.com>
AlexV525 added a commit that referenced this issue Mar 28, 2024
Reverts #2139
Fixes #2167
Reopen #2138

### New Pull Request Checklist

- [x] I have read the
[Documentation](https://pub.dev/documentation/dio/latest/)
- [x] I have searched for a similar pull request in the
[project](https://github.com/cfug/dio/pulls) and found none
- [x] I have updated this branch with the latest `main` branch to avoid
conflicts (via merge from master or rebase)
- [ ] I have added the required tests to prove the fix/feature I'm
adding
- [x] I have updated the documentation (if necessary)
- [x] I have run the tests without failures
- [x] I have updated the `CHANGELOG.md` in the corresponding package

### Additional context and info (if any)

Added tests were fake, so they remained effective after the revert.
@AlexV525 AlexV525 reopened this Mar 29, 2024
@khamidjon
Copy link

the same problem is happening with our project too.

@sdgroot

This comment was marked as off-topic.

@romandrahan

This comment was marked as off-topic.

@sdgroot

This comment was marked as off-topic.

@sagar-acharya-vectorsolutions-ctr

Facing the same issue on my project, do we have any work around for this one.

@Slexom
Copy link

Slexom commented Jun 24, 2024

I solved a similar issue, related to interceptors, downgrading to version 5.4.0, was using 5.4.3+1.

@romandrahan
Copy link

I solved a similar issue, related to interceptors, downgrading to version 5.4.0, was using 5.4.3+1.

@Slexom what was your issue just wondering?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p: dio Targeting `dio` package s: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants