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

Need a way to catch DioException [request cancelled] from the caller code #2088

Closed
stanbav opened this issue Jan 9, 2024 · 3 comments
Closed
Labels
i: duplicate This issue or pull request already exists

Comments

@stanbav
Copy link

stanbav commented Jan 9, 2024

Package

dio

Version

5.3.3

Operating-System

Android, iOS, Web, MacOS, Linux, Windows

Output of flutter doctor -v

[√] Flutter (Channel stable, 3.16.0, on Microsoft Windows [Version 10.0.19045.3803], locale en-US)
    • Flutter version 3.16.0 on channel stable at D:\Projects\2021\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db7ef5bf9f (8 weeks ago), 2023-11-15 11:25:44 -0800
    • Engine revision 74d16627b9
    • Dart version 3.2.0
    • DevTools version 2.28.2

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

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at E:\Android\android-sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: E:\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.5.1)  
    • Visual Studio at E:\Program Files\Microsoft Visual Studio\2022\Community  
    • Visual Studio Community 2022 version 17.5.33424.131
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2022.2)
    • Android Studio at E:\Android\Android Studio
    • 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.6+0-b2043.56-9586694)

[√] VS Code, 64-bit edition (version 1.85.1)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.80.0

[√] Connected device (4 available)
    • SM G935F (mobile) • ad0516024000250aa3 • android-arm64  • Android 8.0.0 (API 26)
    • Windows (desktop) • windows            • windows-x64    • Microsoft Windows [Version 10.0.19045.3803]
    • Chrome (web)      • chrome             • web-javascript • Google Chrome 120.0.6099.200
    • Edge (web)        • edge               • web-javascript • Microsoft Edge 120.0.2210.121

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

• No issues found!

Dart Version

3.2.0

Steps to Reproduce

Is there a way to catch the exception (DioException (DioException [request cancelled]: The request was cancelled.)) thrown from the checkCancelled‎ method ?
It seems to be impossible to do it by using the Dio package's public API and async/await keywords since the _dispatchRequest method is not being awaited for some reason 🤔 and the exception goes unhandled in this case.

Expected Result

Need a way to catch the DioException (DioException [request cancelled]: The request was cancelled.) exception.

Actual Result

The exception DioException (DioException [request cancelled]: The request was cancelled.) goes unhandled if the request is being cancelled using the CancelToken.

@stanbav stanbav added h: need triage This issue needs to be categorized s: bug Something isn't working labels Jan 9, 2024
@stanbav stanbav changed the title Need a way to catch CancelException from the caller code Need a way to catch DioException [request cancelled] from the caller code Jan 9, 2024
@AlexV525
Copy link
Member

AlexV525 commented Jan 9, 2024

Duplicate of #1869

@AlexV525 AlexV525 marked this as a duplicate of #1869 Jan 9, 2024
@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 2024
@stanbav
Copy link
Author

stanbav commented Jan 10, 2024

@AlexV525, according to the Dart SDK collaborator, there is no issue in the Dart SDK dart-lang/sdk#47985 (comment)
If a Future with an error is not awaited - try/catch will not be able to catch it. As I stated in my first post - the Future returned by the catchError method is not awaited, and therefore, there is no way to catch the error by wrapping the fetch method in the try/catch section.
So I believe that shows that something should be done in the Dio package, don't you agree?

@AlexV525
Copy link
Member

So I believe that shows that something should be done in the Dio package, don't you agree?

Not really. If you uncheck the debugger setting with "uncaught exception" then it'll be caught normally. No matter you enabled that feature or not it can be caught eventually.

@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 Apr 3, 2024
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

2 participants