Bloc: catching exception inside mapEventToState breaks future dispatch events

Created on 12 Jun 2019  Â·  4Comments  Â·  Source: felangel/bloc

Thank you for this library and saving us all a ton of development time. I'm using the bloc patter in flutter_web. I do understand flutter web is still in technical preview but if you could take a look at this I'd greatly appreciate it.

Flutter 1.5.4-hotfix.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 7a4c33425d (6 weeks ago) • 2019-04-29 11:05:24 -0700
Engine • revision 52c7a1e849
Tools • Dart 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

Description
Inside my class that extends Bloc<Event, State> I've overridden Stream<State> mapEventToState(Event event) to call a Future function from a repository class. This repository then throws an exception and is caught inside mapEventToState to return a failure state. After catching the exception dispatch no longer works. However, the failure state is properly returned and the ui is updated.

To Reproduce
Steps to reproduce the behavior:
Link to repository demonstrating bug: https://gitlab.com/knittledan/bloc_bug

This is a simple web app that has three buttons. Increment, decrement, throwException

  1. Run the app
  2. Play with the counters buttons -/+
  3. Press the throw exception button
  4. all events stop working

Logs
I don't get any error logs. Logs continue to show up to the point of dispatch but mapEventToState is no longer triggered

➜  bug_code git:(master) flutter doctor -v
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.5 18F132, locale en-US)
    • Flutter version 1.5.4-hotfix.2 at /Users/danielknittle/development/flutter
    • Framework revision 7a4c33425d (6 weeks ago), 2019-04-29 11:05:24 -0700
    • Engine revision 52c7a1e849
    • Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)


[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/danielknittle/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, 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-1248-b01)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[!] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.2.1, Build version 10E1001
    ✗ libimobiledevice and ideviceinstaller are not installed. To install with Brew, run:
        brew update
        brew install --HEAD usbmuxd
        brew link usbmuxd
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.
        For more info, see https://flutter.dev/platform-plugins
      To install:
        brew install cocoapods
        pod setup

[!] Android Studio
    • Android Studio at /Applications/Android Studio 3.4 Preview.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b22)

[!] Android Studio (version 3.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[✓] Android Studio
    • Android Studio at /Applications/Android Studio 3.5 Preview.app/Contents
    • Flutter plugin version 35.3.2
    • Dart plugin version 191.7221
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b02)

[✓] IntelliJ IDEA Ultimate Edition (version 2019.1.3)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 36.0.4
    • Dart plugin version 191.7830

[!] Connected device
    ! No devices available

! Doctor found issues in 5 categories.

Additional context
Again this is flutter for web and I understand it's not fully supported at the moment.

*Simple App
Screen Shot 2019-06-11 at 5 53 36 PM

duplicate

Most helpful comment

Nice! Thanks for looking and apologies I missed the duplicate! At least I can get it to work in release mode.

All 4 comments

Hi @danknittle 👋
Thanks for opening an issue and for the positive feedback!

Based on my initial findings, it seems like an inconsistency in RxDart.
I'll try to dig a bit deeper tomorrow and see if I can understand the underlying issue.

@danknittle this is a duplicate of https://github.com/felangel/bloc/issues/115.

Everything works fine if you run the app in release mode: webdev serve -r.

Nice! Thanks for looking and apologies I missed the duplicate! At least I can get it to work in release mode.

No problem! Yeah as I mentioned in the original issue it looks like the problem is somewhere in dartdevc because by default, webdev serve compiles your app using dartdevc and adding the --release flag uses dart2js.

I would recommend opening an issue for dartdevc because I was also able to confirm that if I take your bloc and run it in a pure dart setting it works as expected.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

1AlexFix1 picture 1AlexFix1  Â·  3Comments

rsnider19 picture rsnider19  Â·  3Comments

frankrod picture frankrod  Â·  3Comments

craiglabenz picture craiglabenz  Â·  3Comments

krusek picture krusek  Â·  3Comments