Catch any FileSystemException
thrown when trying to read the template manifest during flutter create
(#145620)
Fixes https://github.com/flutter/flutter/issues/145423
This commit is contained in:
parent
cc9ac7d13c
commit
69e68f6e04
@ -669,8 +669,18 @@ abstract class CreateBase extends FlutterCommand {
|
|||||||
'templates',
|
'templates',
|
||||||
'template_manifest.json',
|
'template_manifest.json',
|
||||||
);
|
);
|
||||||
|
final String manifestFileContents;
|
||||||
|
try {
|
||||||
|
manifestFileContents = globals.fs.file(manifestPath).readAsStringSync();
|
||||||
|
} on FileSystemException catch (e) {
|
||||||
|
throwToolExit(
|
||||||
|
'Unable to read the template manifest at path "$manifestPath".\n'
|
||||||
|
'Make sure that your user account has sufficient permissions to read this file.\n'
|
||||||
|
'Exception details: $e',
|
||||||
|
);
|
||||||
|
}
|
||||||
final Map<String, Object?> manifest = json.decode(
|
final Map<String, Object?> manifest = json.decode(
|
||||||
globals.fs.file(manifestPath).readAsStringSync(),
|
manifestFileContents,
|
||||||
) as Map<String, Object?>;
|
) as Map<String, Object?>;
|
||||||
return Set<Uri>.from(
|
return Set<Uri>.from(
|
||||||
(manifest['files']! as List<Object?>).cast<String>().map<Uri>(
|
(manifest['files']! as List<Object?>).cast<String>().map<Uri>(
|
||||||
|
@ -7,6 +7,7 @@ import 'dart:convert';
|
|||||||
import 'dart:io' as io;
|
import 'dart:io' as io;
|
||||||
|
|
||||||
import 'package:args/command_runner.dart';
|
import 'package:args/command_runner.dart';
|
||||||
|
import 'package:file/file.dart';
|
||||||
import 'package:file/memory.dart';
|
import 'package:file/memory.dart';
|
||||||
import 'package:file_testing/file_testing.dart';
|
import 'package:file_testing/file_testing.dart';
|
||||||
import 'package:flutter_tools/src/android/gradle_utils.dart' show templateAndroidGradlePluginVersion, templateAndroidGradlePluginVersionForModule, templateDefaultGradleVersion;
|
import 'package:flutter_tools/src/android/gradle_utils.dart' show templateAndroidGradlePluginVersion, templateAndroidGradlePluginVersionForModule, templateDefaultGradleVersion;
|
||||||
@ -3749,6 +3750,40 @@ void main() {
|
|||||||
|
|
||||||
expect(rawManifestJson.contains(expectedDescription), isTrue);
|
expect(rawManifestJson.contains(expectedDescription), isTrue);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testUsingContext('flutter create should tool exit if the template manifest cannot be read', () async {
|
||||||
|
globals.fs.file(globals.fs.path.join(
|
||||||
|
Cache.flutterRoot!,
|
||||||
|
'packages',
|
||||||
|
'flutter_tools',
|
||||||
|
'templates',
|
||||||
|
'template_manifest.json',
|
||||||
|
)).createSync(recursive: true);
|
||||||
|
|
||||||
|
final CreateCommand command = CreateCommand();
|
||||||
|
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||||
|
|
||||||
|
await expectLater(
|
||||||
|
runner.run(<String>[
|
||||||
|
'create',
|
||||||
|
'--no-pub',
|
||||||
|
'--template=plugin',
|
||||||
|
'--project-name=test',
|
||||||
|
projectDir.path,
|
||||||
|
]),
|
||||||
|
throwsToolExit(message: 'Unable to read the template manifest at path'),
|
||||||
|
);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
FileSystem: () => MemoryFileSystem.test(
|
||||||
|
opHandle: (String context, FileSystemOp operation) {
|
||||||
|
if (operation == FileSystemOp.read && context.contains('template_manifest.json')) {
|
||||||
|
throw io.PathNotFoundException(
|
||||||
|
context, const OSError(), 'Cannot open file');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ProcessManager: () => fakeProcessManager,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _createProject(
|
Future<void> _createProject(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user