Unverified Commit 84c8abd0 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] catch StdinException while trying to re-set single char mode (#107256)

parent 26c64569
......@@ -12,6 +12,7 @@ import 'package:vm_service/vm_service.dart';
import '../android/android_device.dart';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/utils.dart';
import '../build_info.dart';
import '../daemon.dart';
......@@ -719,7 +720,11 @@ class RunCommand extends RunCommandBase {
} finally {
// However we exited from the runner, ensure the terminal has line mode
// and echo mode enabled before we return the user to the shell.
globals.terminal.singleCharMode = false;
try {
globals.terminal.singleCharMode = false;
} on StdinException {
// Do nothing, if the STDIN handle is no longer available, there is nothing actionable for us to do at this point
}
}
return FlutterCommandResult(
ExitStatus.success,
......
......@@ -682,6 +682,28 @@ void main() {
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Flutter run catches StdinException while setting terminal singleCharMode to false', () async {
fakeTerminal.hasStdin = false;
final FakeResidentRunner residentRunner = FakeResidentRunner();
final TestRunCommandWithFakeResidentRunner command = TestRunCommandWithFakeResidentRunner();
command.fakeResidentRunner = residentRunner;
try {
await createTestCommandRunner(command).run(<String>[
'run',
'--no-pub',
]);
} catch (err) { // ignore: avoid_catches_without_on_clauses
fail('Expected no error, got $err');
}
expect(fakeTerminal.setSingleCharModeHistory, isEmpty);
}, overrides: <Type, Generator>{
AnsiTerminal: () => fakeTerminal,
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
});
testUsingContext('Flutter run catches service has disappear errors and throws a tool exit', () async {
......@@ -1050,6 +1072,9 @@ class CapturingAppDomain extends AppDomain {
}
class FakeAnsiTerminal extends Fake implements AnsiTerminal {
/// Setting to false will cause operations to Stdin to throw a [StdinException].
bool hasStdin = true;
@override
bool usesTerminalUi = false;
......@@ -1057,7 +1082,12 @@ class FakeAnsiTerminal extends Fake implements AnsiTerminal {
List<bool> setSingleCharModeHistory = <bool>[];
@override
set singleCharMode(bool value) => setSingleCharModeHistory.add(value);
set singleCharMode(bool value) {
if (!hasStdin) {
throw const StdinException('Error setting terminal line mode', OSError('The handle is invalid', 6));
}
setSingleCharModeHistory.add(value);
}
@override
bool get singleCharMode => setSingleCharModeHistory.last;
......
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