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
78b45fb1
Unverified
Commit
78b45fb1
authored
Mar 10, 2020
by
Zachary Anderson
Committed by
GitHub
Mar 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] Throw a tool exit when samples fetch fails (#52355)
parent
3d0082d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
4 deletions
+33
-4
create.dart
packages/flutter_tools/lib/src/commands/create.dart
+11
-4
create_test.dart
...tter_tools/test/commands.shard/permeable/create_test.dart
+22
-0
No files found.
packages/flutter_tools/lib/src/commands/create.dart
View file @
78b45fb1
...
...
@@ -239,13 +239,21 @@ class CreateCommand extends FlutterCommand {
}
final
Uri
snippetsUri
=
Uri
.
https
(
_snippetsHost
,
'snippets/
$sampleId
.dart'
);
return
utf8
.
decode
(
await
_net
.
fetchUrl
(
snippetsUri
));
final
List
<
int
>
data
=
await
_net
.
fetchUrl
(
snippetsUri
);
if
(
data
==
null
||
data
.
isEmpty
)
{
return
null
;
}
return
utf8
.
decode
(
data
);
}
/// Fetches the samples index file from the Flutter docs website.
Future
<
String
>
_fetchSamplesIndexFromServer
()
async
{
final
Uri
snippetsUri
=
Uri
.
https
(
_snippetsHost
,
'snippets/index.json'
);
return
utf8
.
decode
(
await
_net
.
fetchUrl
(
snippetsUri
,
maxAttempts:
2
));
final
List
<
int
>
data
=
await
_net
.
fetchUrl
(
snippetsUri
,
maxAttempts:
2
);
if
(
data
==
null
||
data
.
isEmpty
)
{
return
null
;
}
return
utf8
.
decode
(
data
);
}
/// Fetches the samples index file from the server and writes it to
...
...
@@ -259,8 +267,7 @@ class CreateCommand extends FlutterCommand {
final
String
samplesJson
=
await
_fetchSamplesIndexFromServer
();
if
(
samplesJson
==
null
)
{
throwToolExit
(
'Unable to download samples'
,
exitCode:
2
);
}
else
{
}
else
{
outputFile
.
writeAsStringSync
(
samplesJson
);
globals
.
printStatus
(
'Wrote samples JSON to "
$outputFilePath
"'
);
}
...
...
packages/flutter_tools/test/commands.shard/permeable/create_test.dart
View file @
78b45fb1
...
...
@@ -1283,6 +1283,28 @@ void main() {
HttpClientFactory:
()
=>
()
=>
MockHttpClient
(
200
,
result:
samplesIndexJson
),
});
testUsingContext
(
'Throws tool exit on empty samples index'
,
()
async
{
final
String
outputFile
=
globals
.
fs
.
path
.
join
(
tempDir
.
path
,
'flutter_samples.json'
);
final
CreateCommand
command
=
CreateCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
final
List
<
String
>
args
=
<
String
>[
'create'
,
'--list-samples'
,
outputFile
,
];
await
expectLater
(
runner
.
run
(
args
),
throwsToolExit
(
exitCode:
2
,
message:
'Unable to download samples'
,
));
},
overrides:
<
Type
,
Generator
>{
HttpClientFactory:
()
=>
()
=>
MockHttpClient
(
200
,
result:
''
),
});
testUsingContext
(
'provides an error to the user if samples json download fails'
,
()
async
{
final
String
outputFile
=
globals
.
fs
.
path
.
join
(
tempDir
.
path
,
'flutter_samples.json'
);
final
CreateCommand
command
=
CreateCommand
();
...
...
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