Commit 80b5e207 authored by Casey Hillers's avatar Casey Hillers Committed by GitHub
Browse files

Revert "🎨 Improve exceptions thrown by asset bundle (#114313)"

This reverts commit 0f1d0e39.
parent dccc761e
No related merge requests found
Showing with 10 additions and 41 deletions
+10 -41
......@@ -81,6 +81,9 @@ abstract class AssetBundle {
/// isolate to avoid jank on the main thread.
Future<String> loadString(String key, { bool cache = true }) async {
final ByteData data = await load(key);
if (data == null) {
throw FlutterError('Unable to load asset: $key');
}
// 50 KB of data should take 2-3 ms to parse on a Moto G4, and about 400 μs
// on a Pixel 4.
if (data.lengthInBytes < 50 * 1024) {
......@@ -136,7 +139,7 @@ class NetworkAssetBundle extends AssetBundle {
final HttpClientResponse response = await request.close();
if (response.statusCode != HttpStatus.ok) {
throw FlutterError.fromParts(<DiagnosticsNode>[
_errorSummaryWithKey(key),
ErrorSummary('Unable to load asset: $key'),
IntProperty('HTTP status code', response.statusCode),
]);
}
......@@ -252,10 +255,7 @@ class PlatformAssetBundle extends CachingAssetBundle {
final ByteData? asset =
await ServicesBinding.instance.defaultBinaryMessenger.send('flutter/assets', encoded.buffer.asByteData());
if (asset == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
_errorSummaryWithKey(key),
ErrorDescription('The asset does not exist or has empty data.'),
]);
throw FlutterError('Unable to load asset: $key');
}
return asset;
}
......@@ -284,11 +284,8 @@ class PlatformAssetBundle extends CachingAssetBundle {
}
try {
return await ui.ImmutableBuffer.fromAsset(key);
} on Exception catch (e) {
throw FlutterError.fromParts(<DiagnosticsNode>[
_errorSummaryWithKey(key),
ErrorDescription(e.toString()),
]);
} on Exception {
throw FlutterError('Unable to load asset: $key.');
}
}
}
......@@ -297,10 +294,6 @@ AssetBundle _initRootBundle() {
return PlatformAssetBundle();
}
ErrorSummary _errorSummaryWithKey(String key) {
return ErrorSummary('Unable to load asset: "$key".');
}
/// The [AssetBundle] from which this application was loaded.
///
/// The [rootBundle] contains the resources that were packaged with the
......
......@@ -27,8 +27,6 @@ class TestAssetBundle extends CachingAssetBundle {
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
test('Caching asset bundle test', () async {
final TestAssetBundle bundle = TestAssetBundle();
......@@ -74,8 +72,8 @@ void main() {
expect(
error.toStringDeep(),
'FlutterError\n'
' Unable to load asset: "key".\n'
' HTTP status code: 400\n',
' Unable to load asset: key\n'
' HTTP status code: 404\n',
);
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/39998
......@@ -85,20 +83,4 @@ void main() {
expect(bundle.toString(), 'NetworkAssetBundle#${shortHash(bundle)}($uri)');
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/39998
test('Throws expected exceptions when loading not exists asset', () async {
late final FlutterError error;
try {
await rootBundle.load('not-exists');
} on FlutterError catch (e) {
error = e;
}
expect(
error.message,
equals(
'Unable to load asset: "not-exists".\n'
'The asset does not exist or has empty data.',
),
);
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/56314
}
......@@ -1997,13 +1997,7 @@ void main() {
find.byKey(key),
matchesGoldenFile('image_test.missing.1.png'),
);
expect(
tester.takeException().toString(),
equals(
'Unable to load asset: "missing-asset".\n'
'The asset does not exist or has empty data.',
),
);
expect(tester.takeException().toString(), startsWith('Unable to load asset: '));
await tester.pump();
await expectLater(
find.byKey(key),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment