Skip to content

CachingAssetBundle.loadStructuredData is not forwarding rejection in loadString to returned future. #42390

Closed

Description

@nandin-borjigin

If you call rootBundle.loadStructuredData with a non-existing asset key, it would throw an Unhandled Exception. And you can't catch it by any means (Future.catchError, try await catch etc).

This is because this line does not catch that error and forward it to the returning future.

Steps to Reproduce

main() {
  final String foo = rootBundle.loadStructuredData(
    'some/asset/that/does/not/exists.json', 
    (str) => str
  ).catchError((e) {
    print(e);
    return 'Nothing';
  });

Target Platform: iOS
Target OS version/browser: 13.1
Devices: iOS Simulator (iPhone 11 Pro Max 13.1)

Logs

Too verbose but nothing relavant.
Analyzing app...
No issues found! (ran in 3.2s)
[✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.14.6 18G87, locale en-CN)
    • Flutter version 1.9.1+hotfix.2 at /Users/hashfuture/.flutter-sdk
    • Framework revision 2d2a1ffec9 (5 weeks ago), 2019-09-06 18:39:49 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0


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

[✓] Xcode - develop for iOS and macOS (Xcode 11.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.1, Build version 11A1027
    • CocoaPods version 1.7.5

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 39.0.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

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

[✓] Connected device (1 available)
    • iPhone 11 Pro Max • 6D61E69B-49E2-40BD-B3B6-905EAAE6519A • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-1 (simulator)

• No issues found!

Activity

  1. changed the title [-]`CachedAssetBundle.loadStructuredData` is not forwarding rejection in `loadString` to returned future.[/-] [+]`CachingAssetBundle.loadStructuredData` is not forwarding rejection in `loadString` to returned future.[/+] on Oct 10, 2019
  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    platform-iosiOS applications specifically
    on Oct 10, 2019
  3. added
    a: assetsPackaging, accessing, or using assets
    and removed
    platform-iosiOS applications specifically
    on Oct 16, 2019
  4. markusaksli-nc commented on Sep 25, 2020

    @markusaksli-nc
    Contributor

    Reproducible on the latest master 1.22.0-10.0.pre.340.

    flutter doctor -v
    [√] Flutter (Channel master, 1.22.0-10.0.pre.340, on Microsoft Windows [Version 10.0.19041.508], locale en-US)
        • Flutter version 1.22.0-10.0.pre.340 at C:\Development\flutter_master
        • Framework revision 1fef5912cf (65 minutes ago), 2020-09-23 21:37:08 -0700
        • Engine revision dd35b5b659
        • Dart version 2.10.0 (build 2.10.0-156.0.dev)
    
    
    [√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
        • Android SDK at C:\Users\marku\AppData\Local\Android\sdk
        • Platform android-30, build-tools 30.0.1
        • Java binary at: C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\193.6626763\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web
        • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
    
    [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.6.5)
        • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
        • Visual Studio Community 2019 version 16.6.30320.27
        • Windows 10 SDK version 10.0.18362.0
    
    [√] Android Studio (version 4.0)
        • Android Studio at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\193.6626763
        • Flutter plugin version 47.1.2
        • Dart plugin version 193.7361
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    
    [√] Connected device (6 available)
        • SM G950F (mobile)           • ce12171c51cc001c03 • android-arm64  • Android 9 (API 28)
        • sdk gphone x86 arm (mobile) • emulator-5554      • android-x86    • Android 11 (API 30) (emulator)
        • Windows (desktop)           • windows            • windows-x64    • Microsoft Windows [Version 10.0.19041.508]
        • Web Server (web)            • web-server         • web-javascript • Flutter Tools
        • Chrome (web)                • chrome             • web-javascript • Google Chrome 85.0.4183.102
        • Edge (web)                  • edge               • web-javascript • Microsoft Edge 85.0.564.51
    
    • No issues found!
    

    Updated sample

    import 'package:flutter/services.dart';
    import 'package:flutter/widgets.dart';
    
    main() {
      WidgetsFlutterBinding.ensureInitialized();
      rootBundle
          .loadStructuredData(
              'some/asset/that/does/not/exists.json', (value) => null)
          .catchError((e) => print('caught $e'));
    }

    Should be an easy enough fix, if someone wants to work on this I'd suggest taking a look at the previous attempt that ran into a few test failures first #42394.

  5. nandin-borjigin commented on Sep 30, 2020

    @nandin-borjigin
    Author

    Hi @markusaksli-nc, I'm willing to continue my previous effort to fix this.

    Can you help me with this error in CI? It seems like my forked project's CI machine needs an access to a private repo.

    Error cloning certificates git repo, please make sure you have access to the repository - see instructions above

  6. markusaksli-nc commented on Oct 1, 2020

    @markusaksli-nc
    Contributor

    Not exactly sure what that could be about. Have you tried asking the hackers channel on discord?

  7. nandin-borjigin commented on Oct 5, 2020

    @nandin-borjigin
    Author

    I can't find a hackers channel under /r/FlutterDev

  8. markusaksli-nc commented on Oct 5, 2020

    @markusaksli-nc
    Contributor

    @Nandiin That's the community discord, see Chat for a link to the contributors discord.

  9. maheshj01 commented on Nov 24, 2022

    @maheshj01
    Member

    I can reproduce the issue with or without try catch in the below code sample the exception cannot be caught.

    code sample
    Future<void> main() async {
      WidgetsFlutterBinding.ensureInitialized();
      try{
      final String foo = await rootBundle.loadStructuredData(
        'some/asset/that/does/not/exists.json',
        (str) async => str
      ).catchError((e) {
        print(e);
        return 'Nothing';
      });
      }catch(e){
        print(e);
      }
    }
    logs
    Could not load custom device from config index 0: Expected enabled to be a boolean.
    
    Launching lib/main.dart on iPhone 12 Pro in debug mode...
    Xcode build done.                                           11.1s
    Connecting to VM Service at ws://127.0.0.1:60011/WSU_gr_Lk6E=/ws
    [VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Unable to load asset: "some/asset/that/does/not/exists.json".
    The asset does not exist or has empty data.
    #0      PlatformAssetBundle.load.<anonymous closure> (package:flutter/src/services/asset_bundle.dart:254:9)
    <asynchronous suspension>
    #1      AssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:83:27)
    <asynchronous suspension>
    flutter doctor -v (mac)
    [✓] Flutter (Channel master, 3.6.0-6.0.pre.33, on macOS 12.6 21G115 darwin-arm64,
        locale en-IN)
        • Flutter version 3.6.0-6.0.pre.33 on channel master at
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision a9858ec524 (72 minutes ago), 2022-11-21 10:58:11 -0500
        • Engine revision 46a6b54295
        • Dart version 2.19.0 (build 2.19.0-406.0.dev)
        • DevTools version 2.19.0
        • If those were intentional, you can disregard the above warnings; however it is
          recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-33, build-tools 33.0.0-rc4
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • 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.0.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14A400
        • 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)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.70.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.53.20221101
    
    [✓] Connected device (3 available)
        • iPhone 12 Pro (mobile) • 026D5789-9E78-4AD5-B1B2-3F8D4E7F65E4 • ios
          • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
        • macOS (desktop)        • macos                                • darwin-arm64
          • macOS 12.6 21G115 darwin-arm64
        • Chrome (web)           • chrome                               • web-javascript
          • Google Chrome 107.0.5304.110
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    [✓] Flutter (Channel stable, 3.3.9, on macOS 12.6 21G115 darwin-arm, locale en-IN)
        • Flutter version 3.3.9 on channel stable at /Users/mahesh/Development/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision b8f7f1f986 (24 hours ago), 2022-11-23 06:43:51 +0900
        • Engine revision 8f2221fbef
        • Dart version 2.18.5
        • DevTools version 2.15.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-33, build-tools 33.0.0-rc4
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • 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.0.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14A400
        • 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)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.70.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.53.20221101
    
    [✓] Connected device (3 available)
        • iPhone 12 Pro (mobile) • 026D5789-9E78-4AD5-B1B2-3F8D4E7F65E4 • ios            •
          com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
        • macOS (desktop)        • macos                                • darwin-arm64   • macOS 12.6 21G115 darwin-arm
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 107.0.5304.110
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
  10. added
    P2Important issues not at the top of the work list
    on Jan 3, 2023
  11. self-assigned this
    on Jul 17, 2023
  12. github-actions commented on Aug 2, 2023

    @github-actions

    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.

  13. locked as resolved and limited conversation to collaborators on Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: assetsPackaging, accessing, or using assetsfound in release: 1.22Found to occur in 1.22found in release: 3.3Found to occur in 3.3found in release: 3.6Found to occur in 3.6frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework teamwaiting for PR to land (fixed)A fix is in flight

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions