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

download can not get exception info but just holding #1967

Closed
qinjing100 opened this issue Sep 14, 2023 · 6 comments
Closed

download can not get exception info but just holding #1967

qinjing100 opened this issue Sep 14, 2023 · 6 comments
Labels
i: duplicate This issue or pull request already exists

Comments

@qinjing100
Copy link

qinjing100 commented Sep 14, 2023

Package

dio

Version

5.3.2

Operating-System

Android, MacOS

Output of flutter doctor -v

[✓] Flutter (Channel master, 3.12.0-14.0.pre.30, on macOS 13.4.1 22F770820d darwin-x64, locale zh-Hans-HK)
    • Flutter version 3.12.0-14.0.pre.30 on channel master at /usr/local/Caskroom/flutter/2.10.3/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ddb16b7d92 (2 months ago), 2023-07-03 14:27:33 -0400
    • Engine revision 987b621eac
    • Dart version 3.1.0 (build 3.1.0-262.0.dev)
    • DevTools version 2.25.0
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc2)
    • Android SDK at /Users/bruce/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0-rc2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.11.3

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

[✓] Android Studio (version 2021.2)
    • Android Studio at /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 11.0.12+0-b1504.28-7817840)

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

[✓] Connected device (3 available)
    • Nokia 7 plus (mobile) • B2NGAC6811301873 • android-arm64  • Android 9 (API 28)
    • macOS (desktop)       • macos            • darwin-x64     • macOS 13.4.1 22F770820d darwin-x64
    • Chrome (web)          • chrome           • web-javascript • Google Chrome 116.0.5845.187

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

• No issues found!

Dart Version

3.1.0

Steps to Reproduce

Future<void> tempDownloadFile(uri, fileName) async {
    String savePath = '/storage/emulated/0/Download/$fileName';
    Dio dio = Dio(BaseOptions(
      connectTimeout: const Duration(seconds: 3),
      receiveTimeout: const Duration(seconds: 5),
    ));
    try {
      Response response = await dio.download(
        uri,
        savePath,
        onReceiveProgress: (rcv, total) {
          if (total != -1) {
            print(
                'received: ${rcv.toStringAsFixed(0)} out of total: ${total.toStringAsFixed(0)}');
            setState(() {
              progress = ((rcv / total) * 100).toStringAsFixed(0);
            });
          }
        },
        deleteOnError: false,
      );
      print('status=${response.statusCode}');
      print('Download complete.');
      setState(() {
        isDownloading = false;
        isDownloaded = true;
      });
    } on DioException catch (error) {
      // error
      print('DioError: ${error.toString()}');
      setState(() {
        isDownloading = false;
        isDownloaded = false;
      });
    } catch (e) {
      print('download error: $e');
      setState(() {
        isDownloading = false;
        isDownloaded = false;
      });
    } finally {
      dio.close();
    }
  }

Expected Result

I/flutter (16130): DioError: DioException [connection timeout]: The request connection took longer than 0:00:03.000000. It was aborted.

Actual Result

when download uri is https://img.lanrentuku.com/img/allimg/1502/46-15022R01Z10-L.jpg, ok;
but when give an bad uri, e.g. https://img.lanrentuku.com.cn/img/allimg/1502/46-15022R01Z10-L.jpg, no DioException log.
when hot reloading, console print the above error.
And can not catch any error when the uri return 404 status.
But in dart cmd script, it works well. when any error occurs, I can get the error message in log.

@qinjing100 qinjing100 added h: need triage This issue needs to be categorized s: bug Something isn't working labels Sep 14, 2023
@kuhnroyal
Copy link
Member

Your bad URI does not return 404, it just does not exist, so it will run into a timeout. What is your timeout set to?

@qinjing100
Copy link
Author

Your bad URI does not return 404, it just does not exist, so it will run into a timeout. What is your timeout set to?

no matter the bad uri is return 404 or connection can not established (handshake failed),i can not catch the expected exception that i can do some other logics.

@qinjing100
Copy link
Author

Your bad URI does not return 404, it just does not exist, so it will run into a timeout. What is your timeout set to?

I just set base options below
BaseOptions(
connectTimeout: const Duration(seconds: 3),
receiveTimeout: const Duration(seconds: 5),
)

In my case, I should check the uri connectivity first, then download ?

but above log, when I hot reload, the dio exception print, why ?

@AlexV525
Copy link
Member

As I tested in a Flutter app:

I/flutter (15586): DioError: DioException [unknown]: null
I/flutter (15586): Error: SocketException: Failed host lookup: 'img.lanrentuku.com.cn' (OS Error: No address associated with hostname, errno = 7)

@AlexV525 AlexV525 added i: cannot reproduce and removed h: need triage This issue needs to be categorized s: bug Something isn't working labels Sep 15, 2023
@kuhnroyal
Copy link
Member

@qinjing100 This may be influenced by your Flutter app configuration, zones or error handlers.
If you can provide a full sample, we might be able too look into it, otherwise there is no way to help you.

@qinjing100
Copy link
Author

@qinjing100 This may be influenced by your Flutter app configuration, zones or error handlers. If you can provide a full sample, we might be able too look into it, otherwise there is no way to help you.

Sorry, it's my problem. I use VS Code debug flutter app, but the Uncaught Exception checkbox tipped automaticlly.
I found the error on StackOverflow .
dart-flutter-debugger-stops-on-caught-exceptions
When I run the code in command line, flutter run -v , it works well
But in VS Code, it stop when caught exception (e.g. 404)
image

Thanks a lot.

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 15, 2023
@AlexV525 AlexV525 added i: duplicate This issue or pull request already exists and removed i: cannot reproduce labels Sep 15, 2023
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