Repository navigation
[tool_crash] _TypeError: (#0 AppResourceBundle.translationFor (package:flutter_tools/src/localizations/gen_l10n_types.dart:637:70)) #138297
Copy link
Copy link
Closed
Labels
a: internationalizationSupporting other languages or locales. (aka i18n)Supporting other languages or locales. (aka i18n)c: crashStack traces logged to the consoleStack traces logged to the consoler: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.
Description
Command
flutter --no-color run --machine --track-widget-creation --device-id=OF6LHMB9A2101175 --start-paused --dart-define=flutter.inspector.structuredErrors=true lib\main.dart
Steps to Reproduce
- ...
- ...
- ...
Logs
_TypeError: (#0 AppResourceBundle.translationFor (package:flutter_tools/src/localizations/gen_l10n_types.dart:637:70))
#0 AppResourceBundle.translationFor (package:flutter_tools/src/localizations/gen_l10n_types.dart:637:70)
#1 new Message (package:flutter_tools/src/localizations/gen_l10n_types.dart:353:42)
#2 LocalizationsGenerator.loadResources.<anonymous closure> (package:flutter_tools/src/localizations/gen_l10n.dart:908:67)
#3 MappedIterator.moveNext (dart:_internal/iterable.dart:393:20)
#4 new _GrowableList._ofOther (dart:core-patch/growable_array.dart:202:26)
#5 new _GrowableList.of (dart:core-patch/growable_array.dart:152:26)
#6 new List.of (dart:core-patch/array_patch.dart:47:28)
#7 Iterable.toList (dart:core/iterable.dart:495:7)
#8 LocalizationsGenerator.loadResources (package:flutter_tools/src/localizations/gen_l10n.dart:910:8)
#9 generateLocalizations (package:flutter_tools/src/localizations/gen_l10n.dart:73:9)
#10 GenerateLocalizationsTarget.build (package:flutter_tools/src/build_system/targets/localizations.dart:60:11)
#11 _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:853:27)
<asynchronous suspension>
#12 FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:620:16)
<asynchronous suspension>
#13 generateLocalizationsSyntheticPackage (package:flutter_tools/src/dart/generate_synthetic_packages.dart:56:30)
<asynchronous suspension>
#14 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1592:7)
<asynchronous suspension>
#15 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1297:27)
<asynchronous suspension>
#16 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#17 CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
[✓] Flutter (Channel stable, 3.13.8, on Microsoft Windows [Version 10.0.22621.2506], locale en-GB)
• Flutter version 3.13.8 on channel stable at D:\Flutter\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 6c4930c4ac (3 weeks ago), 2023-10-18 10:57:55 -0500
• Engine revision 767d8c75e8
• Dart version 3.1.4
• DevTools version 2.25.0
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at C:\Users\Administrator\AppData\Local\Android\sdk
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[✓] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[✗] Visual Studio - develop Windows apps
✗ Visual Studio not installed; this is necessary to develop Windows apps.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components
[✓] Android Studio (version 2022.3)
• Android Studio at C:\Program Files\Android\Android Studio
• 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 17.0.6+0-b2043.56-10027231)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.1)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2023.1.2
• 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
[✓] VS Code (version 1.84.1)
• VS Code at C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.76.0
[✓] Connected device (4 available)
• SHV46 (mobile) • OF6LHMB9A2101175 • android-arm64 • Android 11 (API 30)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22621.2506]
• Chrome (web) • chrome • web-javascript • Google Chrome 118.0.5993.88
• Edge (web) • edge • web-javascript • Microsoft Edge 119.0.2151.58
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 2 categories.
Flutter Application Metadata
Type: malformed
Version: 1.0.0+1
Material: true
Android X: false
Module: false
Plugin: false
Android package: null
iOS bundle identifier: null
Creation channel: null
Creation framework version: null
Plugins
firebase_core-2.22.0
firebase_core_web-2.8.1
firebase_messaging-14.7.4
firebase_messaging_web-3.5.13
flutter_native_select-1.0.1
flutter_native_splash-2.2.19
path_provider_linux-2.2.1
path_provider_windows-2.2.1
restart_app-1.2.1
shared_preferences-2.1.0
shared_preferences_android-2.2.1
shared_preferences_foundation-2.3.4
shared_preferences_linux-2.3.2
shared_preferences_web-2.2.1
shared_preferences_windows-2.3.2
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
a: internationalizationSupporting other languages or locales. (aka i18n)Supporting other languages or locales. (aka i18n)c: crashStack traces logged to the consoleStack traces logged to the consoler: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.
Activity
danagbemava-nc commentedon Nov 13, 2023
Labeling based on the report above.
Meshavegas commentedon Nov 15, 2023
Thank you but i solved it. :)
andrewkolos commentedon Nov 15, 2023
@Meshavegas, I'm glad you were able solve whatever was causing this crash 🙂. Still, the
flutterCLI tool should never crash, which probably means you encountered a bug. I would like to find that bug. If you are willing and able, could you share what was causing this crash?Meshavegas commentedon Nov 16, 2023
It appears that the Flutter CLI crash i encountered might have been triggered by a shortage of disk space on my computer. I point out that the substantial resources consumption by Android Studio, when in use, could be a contributing factor to the Flutter CLI crash.
In summary, my hypothesis is that the insufficient disk space, potentially exacerbated by the resource demands of Android Studio, could have led to the instability of the Flutter CLI.
I solved the issue by either freeing up space and upgrading my storage capacity might be a practical step to mitigate such problems in the future.
andrewkolos commentedon Nov 27, 2023
I've finally done some digging here. Here's what I found.
My reading of the stack trace:
LocalizationsGenerator.loadResources: During build, we read the app's arb files (each of which contains JSON containing resource-value pairs for various locales).Here's the line where the
TypeErrorhappens:AppResourceBundle.translationFor: in one of those ARB files, we lookup the translation for the givenresourceIdfrom aMap<String, Object?>. We try to cast this to aString?. Here is that line of code:flutter/packages/flutter_tools/lib/src/localizations/gen_l10n_types.dart
Line 637 in ff838bc
The indexing operation here shouldn't result in a
TypeError, so I'm thinking thatresources[resourceId]must be non-null and also not aString.resourcesis generated during the construction of theAppResourceBundleby a simplejson.decodeoperation, and I don't see any code that could overwrite any values. This leads me to believe thatflutterwas trying to work with an invalid ARB file. To test this, I tried making a minimal repro, and I was successful.gen_l10n_example.helloWorldentry's value from"¡Hola Mundo!"to{}.flutter cleanandflutter pub get(which will runflutter gen_l10n).This resulted in a crash containing a link to create a new GitHub issue that looked identical to this issue. Here is my stack trace:
Details
_TypeError: (#0 AppResourceBundle.translationFor (package:flutter_tools/src/localizations/gen_l10n_types.dart:649:70))
In conclusion, when parsing arb files,
fluttershould also validate the contents. If the contents are invalid, we it throw aToolExitwith a helpful message instead of crashing. I've opened #139035 to do thisAdd type validation to non-template .arb file parsing logic (#139035)
github-actions commentedon Dec 12, 2023
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 -vand a minimal reproduction of the issue.Add type validation to non-template .arb file parsing logic (flutter#…