[flutter_tools] exit with helpful message if where is missing on windows (#65112)
This commit is contained in:
parent
68c1b441be
commit
d3fd62c843
@ -8,6 +8,7 @@ import 'package:meta/meta.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../globals.dart' as globals;
|
||||
import 'common.dart';
|
||||
import 'file_system.dart';
|
||||
import 'io.dart';
|
||||
import 'logger.dart';
|
||||
@ -289,7 +290,18 @@ class _WindowsUtils extends OperatingSystemUtils {
|
||||
@override
|
||||
List<File> _which(String execName, { bool all = false }) {
|
||||
// `where` always returns all matches, not just the first one.
|
||||
final ProcessResult result = _processManager.runSync(<String>['where', execName]);
|
||||
ProcessResult result;
|
||||
try {
|
||||
result = _processManager.runSync(<String>['where', execName]);
|
||||
} on ArgumentError {
|
||||
// `where` could be missing if system32 is not on the PATH.
|
||||
throwToolExit(
|
||||
'Cannot find the executable for `where`. This can happen if the System32 '
|
||||
'folder (e.g. C:\\Windows\\System32 ) is removed from the PATH environment '
|
||||
'variable. Ensure that this is present and then try again after restarting '
|
||||
'the terminal and/or IDE.'
|
||||
);
|
||||
}
|
||||
if (result.exitCode != 0) {
|
||||
return const <File>[];
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
@ -62,6 +63,13 @@ void main() {
|
||||
});
|
||||
|
||||
group('which on Windows', () {
|
||||
testWithoutContext('throws tool exit if where throws an argument error', () async {
|
||||
when(mockProcessManager.runSync(<String>['where', kExecutable]))
|
||||
.thenThrow(ArgumentError('Cannot find executable for where'));
|
||||
final OperatingSystemUtils utils = createOSUtils(FakePlatform(operatingSystem: 'windows'));
|
||||
|
||||
expect(() => utils.which(kExecutable), throwsA(isA<ToolExit>()));
|
||||
});
|
||||
testWithoutContext('returns null when executable does not exist', () async {
|
||||
when(mockProcessManager.runSync(<String>['where', kExecutable]))
|
||||
.thenReturn(ProcessResult(0, 1, null, null));
|
||||
|
Loading…
x
Reference in New Issue
Block a user