Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
0f1d0e39
Unverified
Commit
0f1d0e39
authored
Nov 01, 2022
by
Alex Li
Committed by
GitHub
Nov 01, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🎨
Improve exceptions thrown by asset bundle (#114313)
parent
c2edb20f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
10 deletions
+41
-10
asset_bundle.dart
packages/flutter/lib/src/services/asset_bundle.dart
+14
-7
asset_bundle_test.dart
packages/flutter/test/services/asset_bundle_test.dart
+20
-2
image_test.dart
packages/flutter/test/widgets/image_test.dart
+7
-1
No files found.
packages/flutter/lib/src/services/asset_bundle.dart
View file @
0f1d0e39
...
...
@@ -81,9 +81,6 @@ 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
)
{
...
...
@@ -139,7 +136,7 @@ class NetworkAssetBundle extends AssetBundle {
final
HttpClientResponse
response
=
await
request
.
close
();
if
(
response
.
statusCode
!=
HttpStatus
.
ok
)
{
throw
FlutterError
.
fromParts
(<
DiagnosticsNode
>[
ErrorSummary
(
'Unable to load asset:
$key
'
),
_errorSummaryWithKey
(
key
),
IntProperty
(
'HTTP status code'
,
response
.
statusCode
),
]);
}
...
...
@@ -255,7 +252,10 @@ class PlatformAssetBundle extends CachingAssetBundle {
final
ByteData
?
asset
=
await
ServicesBinding
.
instance
.
defaultBinaryMessenger
.
send
(
'flutter/assets'
,
encoded
.
buffer
.
asByteData
());
if
(
asset
==
null
)
{
throw
FlutterError
(
'Unable to load asset:
$key
'
);
throw
FlutterError
.
fromParts
(<
DiagnosticsNode
>[
_errorSummaryWithKey
(
key
),
ErrorDescription
(
'The asset does not exist or has empty data.'
),
]);
}
return
asset
;
}
...
...
@@ -284,8 +284,11 @@ class PlatformAssetBundle extends CachingAssetBundle {
}
try
{
return
await
ui
.
ImmutableBuffer
.
fromAsset
(
key
);
}
on
Exception
{
throw
FlutterError
(
'Unable to load asset:
$key
.'
);
}
on
Exception
catch
(
e
)
{
throw
FlutterError
.
fromParts
(<
DiagnosticsNode
>[
_errorSummaryWithKey
(
key
),
ErrorDescription
(
e
.
toString
()),
]);
}
}
}
...
...
@@ -294,6 +297,10 @@ 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
...
...
packages/flutter/test/services/asset_bundle_test.dart
View file @
0f1d0e39
...
...
@@ -27,6 +27,8 @@ class TestAssetBundle extends CachingAssetBundle {
}
void
main
(
)
{
TestWidgetsFlutterBinding
.
ensureInitialized
();
test
(
'Caching asset bundle test'
,
()
async
{
final
TestAssetBundle
bundle
=
TestAssetBundle
();
...
...
@@ -72,8 +74,8 @@ void main() {
expect
(
error
.
toStringDeep
(),
'FlutterError
\n
'
' Unable to load asset:
key
\n
'
' HTTP status code: 40
4
\n
'
,
' Unable to load asset:
"key".
\n
'
' HTTP status code: 40
0
\n
'
,
);
},
skip:
isBrowser
);
// https://github.com/flutter/flutter/issues/39998
...
...
@@ -83,4 +85,20 @@ 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
}
packages/flutter/test/widgets/image_test.dart
View file @
0f1d0e39
...
...
@@ -1997,7 +1997,13 @@ void main() {
find
.
byKey
(
key
),
matchesGoldenFile
(
'image_test.missing.1.png'
),
);
expect
(
tester
.
takeException
().
toString
(),
startsWith
(
'Unable to load asset: '
));
expect
(
tester
.
takeException
().
toString
(),
equals
(
'Unable to load asset: "missing-asset".
\n
'
'The asset does not exist or has empty data.'
,
),
);
await
tester
.
pump
();
await
expectLater
(
find
.
byKey
(
key
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment