Unverified Commit 4b73746a authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Catch filesystem exception from flutter create (#38101)

parent b8484e34
......@@ -4,6 +4,7 @@
import 'package:mustache/mustache.dart' as mustache;
import 'base/common.dart';
import 'base/file_system.dart';
import 'cache.dart';
import 'globals.dart';
......@@ -62,13 +63,22 @@ class Template {
Map<String /* relative */, String /* absolute source */> _templateFilePaths;
/// Render the template into [directory].
///
/// May throw a [ToolExit] if the directory is not writable.
int render(
Directory destination,
Map<String, dynamic> context, {
bool overwriteExisting = true,
bool printStatusWhenWriting = true,
}) {
destination.createSync(recursive: true);
try {
destination.createSync(recursive: true);
} on FileSystemException catch (err) {
printError(err.toString());
throwToolExit('Failed to flutter create at ${destination.path}.');
return 0;
}
int fileCount = 0;
/// Returns the resolved destination path corresponding to the specified
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/template.dart';
import 'package:mockito/mockito.dart';
import 'src/common.dart';
import 'src/testbed.dart';
void main() {
Testbed testbed;
setUp(() {
testbed = Testbed();
});
test('Template.render throws ToolExit when FileSystem exception is raised', () => testbed.run(() {
final Template template = Template(fs.directory('examples'), fs.currentDirectory);
final MockDirectory mockDirectory = MockDirectory();
when(mockDirectory.createSync(recursive: true)).thenThrow(const FileSystemException());
expect(() => template.render(mockDirectory, <String, Object>{}),
throwsA(isInstanceOf<ToolExit>()));
}));
}
class MockDirectory extends Mock implements Directory {}
Markdown is supported
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