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

Unable to catch DioError #655

Closed
psgainz opened this issue Jan 16, 2020 · 19 comments
Closed

Unable to catch DioError #655

psgainz opened this issue Jan 16, 2020 · 19 comments

Comments

@psgainz
Copy link

psgainz commented Jan 16, 2020

New Issue Checklist

  • [ Yes ] I have searched for a similar issue in the project and found none

Issue Info

Info Value
Platform Name Flutter - Android
Platform Version 6.0
Dio Version e.g. 3.0.7
Visual Studio Code VSCode 1.36.0
Repro rate 100%
Repro with our demo prj NA
Demo project link NA

Issue Description and Steps

Code Snippet

try {
      response = await dio.post(
        'https://wendux.github.io/xsddddd',
        data: data,
        onSendProgress: (sent, total) {
          if (total != -1) {
            pr.update(
              progress: (sent / total * 100),
              message: 'Sending File : ' + ((sent / total * 100).toInt()).toStringAsFixed(0) + "%",
            );
            if(sent == total) print('Sent');
          }
        },
        //Handle Exceptions here (Issues in receiving data - memory or else)
        onReceiveProgress: (received, total) {
          if(total != -1) {
            pr.update(
              progress: (received / total * 100),
              message: 'Receiving Data : ' + ((received / total * 100).toInt()).toStringAsFixed(0) + "%",
            );
            if(received == total) print('Received');
          }
        }
      );
    }
    on DioError catch(e) {
      print(e.response.data);
      print(e.response.headers);
      print(e.response.request);
      await showAlertDialog(context,
       alertTitle: 'Internet Connection Error',
        alertText: 'Please check you internet connection & try again',
        numberButtons: 1
      );
      cancelOp = true;

    }

In dispatchRequest, exception being thrown here

DioError err = assureDioError(e, options);
      throw err;

However it is not caught by the above code snippet

@ffpetrovic
Copy link

Same here, can't catch with catch(e) in general, not just on DioError.

@psgainz
Copy link
Author

psgainz commented Feb 3, 2020

It looks like the issue is due to Flutter framework. Many exceptions of several packages are not caught when running the app in DEBUG Mode. However, I noticed that when you run your application in RELEASE Mode, everything seems to work fine (though mostly, & I don't think every time). Waiting for the dio team to share their opinion on it @ffpetrovic

@ffpetrovic
Copy link

Does latest flutter have this issue? @psgainz

@psgainz
Copy link
Author

psgainz commented Feb 3, 2020

Unfortunately yes!
The only option is to test in RELEASE Mode whenever you feel to test the exception.

@ffpetrovic
Copy link

Thanks @psgainz
Did you find this somewhere? Is there an issue for this on the flutter repo?

@psgainz
Copy link
Author

psgainz commented Feb 3, 2020

I accidentally encountered it while testing in RELEASE Mode. Also, in some stackoverflow post, I read that this issue also persists for google_sign_in package. Exceptions are not caught when thrown by the package. Only in RELEASE Mode, some exceptions are caught, while some exceptions simply do not occur.

https://stackoverflow.com/questions/51914691/flutter-platform-exception-upon-cancelling-google-sign-in-flow

@ffpetrovic
Copy link

ffpetrovic commented Feb 3, 2020

Yes, I have had this problem with google sign in and also read that release mode fixes it.

@urusai88
Copy link

urusai88 commented Feb 5, 2020

Hello everybody! I have a same problem without any "google signin flow", i am just trying to make http request.
Standart dart HttpClient works well.

@psgainz
Copy link
Author

psgainz commented Feb 11, 2020

Closing the issue as the exception works correctly in RELEASE Mode

@psgainz psgainz closed this as completed Feb 11, 2020
@ffpetrovic
Copy link

Debugging in RELEASE mode is very limited. This is not a valid excuse.

@talski
Copy link

talski commented Aug 21, 2020

a workaround is disable all breakpoints in run tab sidebar, the error will be catched and the app will flow

@VenatusSimpleX
Copy link

@talski's workaround is not optimal, as we want to catch all uncaught error if possible to prevent accidental crashes. Any plans at all to fix this?

@RaoSaqib7860
Copy link

i am handle in this way on debug mode I know its not good practice
Options(
headers: {'Authorization': 'Bearer $token'},
followRedirects: false,
validateStatus: (status) {
return status <= 500;
}
)

@hongdnn
Copy link

hongdnn commented Feb 15, 2021

There are some exceptions that you are not caught.
If you don't know how to handle with those exceptions, go to Run in the left sidebar, at the Breakpoints area, unselect the "Uncaught Exceptions" checkbox.

@hectorAguero
Copy link

hectorAguero commented Jun 18, 2021

Now the error with the google signIn flow is already fixed in the dart sdk, I'll try to upgrade to latest dart a downloaded version of the dio package, but now leaks other exception types (but I didn't try the snippet of this issue).

By the way, this issue should not be closed.

Google Sign Flow issue: flutter/flutter#45146
Dart SDK issue: dart-lang/sdk#37953

@a7md0
Copy link

a7md0 commented Nov 12, 2021

Any updates on this? Using latest dart/flutter versions still causing this issue

Flutter (Channel stable, 2.5.3)
Dart SDK version: 2.14.4 (stable)

All these issues discussing the same DioError unhandled exception
#1171 #1253 #1290 #1306

@dawid-niedzwiecki
Copy link

Any updates? This stil occurs.

@tpkowastaken
Copy link

Can confirm. Just encountered it with this code:

    try{
      await Dio().download(fileUrl, savePath, onReceiveProgress: (count, total) {
        final value = count / total;
        if (valueNotifier.value != value) {
          valueNotifier.value = value;
        }
      });
    }
    catch(e){
      valueNotifier.value = -2;
      return;
    }

@urusai88
Copy link

urusai88 commented Dec 2, 2023

hey? the issue still occurs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests