flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.19k stars 27.49k forks source link

Unable to capture exception from plugin #47488

Closed ctippur closed 4 years ago

ctippur commented 4 years ago

Steps to Reproduce

I am trying to use flutube plugin which is throwing an exception. I am unable to catch the exception in my code. Here is the code snippet.

Widget _playVideo() {
    List<String> vidURL = [];
    vidURL.add(location);
    try {
      return FluTube.playlist(
        vidURL,
        autoInitialize: true,
        aspectRatio: 16 / 9,
        allowMuting: false,
        showControls: true,
        looping: false,
        autoPlay: true,
        fullscreenByDefault: false,
        deviceOrientationAfterFullscreen: [
          DeviceOrientation.landscapeRight,
          DeviceOrientation.landscapeLeft,
        ],
        systemOverlaysAfterFullscreen: SystemUiOverlay.values,
        onVideoStart: () async {
          try {
            startVideoRecording();
          } catch (e) {
            print('***onVideoStart: ${e.toString()}');
          }
        },
        onVideoEnd: () async {
          try {
            onStop(context);
          } catch (e) {
            print('***onVideoEnd: ${e.toString()}');
          }
        },
      );
    } catch (e) {
      print("***Exception in youtube video " + e.toString());
    }
    return null;
  }

Flutube errors out most of the time without playing the video. I want to be able to catch the error and wrap some logic to retry. Since I cant catch the error, I am unable to write any logic. Appreciate any pointers.

Android/iOS

Logs

Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 0
<asynchronous suspension>
#2      FluTubeState._initialize 
package:flutube/src/flutube_player.dart:140
#3      FluTubeState.initState 
package:flutube/src/flutube_player.dart:132
#4      StatefulElement._firstBuild 
package:flutter/…/widgets/framework.dart:4355
#5      ComponentElement.mount 
package:flutter/…/widgets/framework.dart:4201
#6      Element.inflateWidget 
package:flutter/…/widgets/framework.dart:3194
#7      Element.updateChild 
package:flutter/…/widgets/framework.dart:2988
#8      SingleChildRenderObjectElement.mount 
package:flutter/…/widgets/framework.dart:5445
#9      Element.inflateWidget 
package:flutter/…/widgets/framework.dart:3194
#10     Element.updateChild (package:flutter/s<…>
Bunch of unused plugins
[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.14.6 18G1012, locale en-US)
    • Flutter version 1.12.13+hotfix.5 at /Users/shekartippur/playground/cyclopscloud/cyclopsglobal/flutter/flutter
    • Framework revision 27321ebbad (9 days ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/shekartippur/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.3, Build version 10G8
    • CocoaPods version 1.6.1

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 31.3.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] IntelliJ IDEA Community Edition (version 2017.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 29.0.1
    • Dart plugin version 173.3727.108

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

[✓] Connected device (1 available)
    • iPhone Xʀ • 17E002DE-29B0-4299-8257-375F28C36925 • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-4 (simulator)

• No issues found!
iapicca commented 4 years ago

Hi @ctippur I'm not familiar with the 3rd party plugin flutube, but the good old try / catch seems working just fine in Dart 2.6

sample ```dart void main() { _syncTryCatch(); _asyncTryCatch(); } const String _error_message = 'error caught'; bool get _bool => null; Future get _futureBool async { await Future.delayed(const Duration(seconds: 1),); return _bool; } void _syncTryCatch() { try { print(_bool?'true':'false'); } catch (e) { print(_error_message); } } void _asyncTryCatch() async { try { print(await _futureBool?'true':'false'); } catch (e) { print(_error_message); } } ```

you may want to open an issue in the plugin's dedicated github

Closing, as this isn't an issue with Flutter itself, if you disagree please write in the comments and I will reopen it Thank you

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.