Unverified Commit 2c898f68 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Remove writelnStderr (#16058)

Paying off technical debt...
parent cab8242f
...@@ -61,17 +61,6 @@ Future<int> run( ...@@ -61,17 +61,6 @@ Future<int> run(
}); });
} }
/// Writes the [string] to one of the standard output streams.
@visibleForTesting
typedef void WriteCallback([String string]);
/// Writes a line to STDERR.
///
/// Overwrite this in tests to avoid spurious test output.
// TODO(tvolkert): Remove this in favor of context[Stdio]
@visibleForTesting
WriteCallback writelnStderr = stderr.writeln;
Future<int> _handleToolError( Future<int> _handleToolError(
dynamic error, dynamic error,
StackTrace stackTrace, StackTrace stackTrace,
...@@ -81,9 +70,9 @@ Future<int> _handleToolError( ...@@ -81,9 +70,9 @@ Future<int> _handleToolError(
String getFlutterVersion(), String getFlutterVersion(),
) async { ) async {
if (error is UsageException) { if (error is UsageException) {
writelnStderr(error.message); stderr.writeln(error.message);
writelnStderr(); stderr.writeln();
writelnStderr( stderr.writeln(
"Run 'flutter -h' (or 'flutter <command> -h') for available " "Run 'flutter -h' (or 'flutter <command> -h') for available "
'flutter commands and options.' 'flutter commands and options.'
); );
...@@ -91,11 +80,11 @@ Future<int> _handleToolError( ...@@ -91,11 +80,11 @@ Future<int> _handleToolError(
return _exit(64); return _exit(64);
} else if (error is ToolExit) { } else if (error is ToolExit) {
if (error.message != null) if (error.message != null)
writelnStderr(error.message); stderr.writeln(error.message);
if (verbose) { if (verbose) {
writelnStderr(); stderr.writeln();
writelnStderr(stackTrace.toString()); stderr.writeln(stackTrace.toString());
writelnStderr(); stderr.writeln();
} }
return _exit(error.exitCode ?? 1); return _exit(error.exitCode ?? 1);
} else if (error is ProcessExit) { } else if (error is ProcessExit) {
...@@ -108,20 +97,20 @@ Future<int> _handleToolError( ...@@ -108,20 +97,20 @@ Future<int> _handleToolError(
} }
} else { } else {
// We've crashed; emit a log report. // We've crashed; emit a log report.
writelnStderr(); stderr.writeln();
if (!reportCrashes) { if (!reportCrashes) {
// Print the stack trace on the bots - don't write a crash report. // Print the stack trace on the bots - don't write a crash report.
writelnStderr('$error'); stderr.writeln('$error');
writelnStderr(stackTrace.toString()); stderr.writeln(stackTrace.toString());
return _exit(1); return _exit(1);
} else { } else {
flutterUsage.sendException(error, stackTrace); flutterUsage.sendException(error, stackTrace);
if (error is String) if (error is String)
writelnStderr('Oops; flutter has exited unexpectedly: "$error".'); stderr.writeln('Oops; flutter has exited unexpectedly: "$error".');
else else
writelnStderr('Oops; flutter has exited unexpectedly.'); stderr.writeln('Oops; flutter has exited unexpectedly.');
await CrashReportSender.instance.sendReport( await CrashReportSender.instance.sendReport(
error: error, error: error,
...@@ -130,13 +119,13 @@ Future<int> _handleToolError( ...@@ -130,13 +119,13 @@ Future<int> _handleToolError(
); );
try { try {
final File file = await _createLocalCrashReport(args, error, stackTrace); final File file = await _createLocalCrashReport(args, error, stackTrace);
writelnStderr( stderr.writeln(
'Crash report written to ${file.path};\n' 'Crash report written to ${file.path};\n'
'please let us know at https://github.com/flutter/flutter/issues.', 'please let us know at https://github.com/flutter/flutter/issues.',
); );
return _exit(1); return _exit(1);
} catch (error) { } catch (error) {
writelnStderr( stderr.writeln(
'Unable to generate crash report due to secondary error: $error\n' 'Unable to generate crash report due to secondary error: $error\n'
'please let us know at https://github.com/flutter/flutter/issues.', 'please let us know at https://github.com/flutter/flutter/issues.',
); );
......
...@@ -30,13 +30,11 @@ void main() { ...@@ -30,13 +30,11 @@ void main() {
setUp(() async { setUp(() async {
tools.crashFileSystem = new MemoryFileSystem(); tools.crashFileSystem = new MemoryFileSystem();
tools.writelnStderr = ([_]) { };
setExitFunctionForTests((_) { }); setExitFunctionForTests((_) { });
}); });
tearDown(() { tearDown(() {
tools.crashFileSystem = const LocalFileSystem(); tools.crashFileSystem = const LocalFileSystem();
tools.writelnStderr = const Stdio().stderr.writeln;
restoreExitFunction(); restoreExitFunction();
}); });
...@@ -119,6 +117,8 @@ void main() { ...@@ -119,6 +117,8 @@ void main() {
.map((FileSystemEntity e) => e.path).toList(); .map((FileSystemEntity e) => e.path).toList();
expect(writtenFiles, hasLength(1)); expect(writtenFiles, hasLength(1));
expect(writtenFiles, contains('flutter_01.log')); expect(writtenFiles, contains('flutter_01.log'));
}, overrides: <Type, Generator>{
Stdio: () => const _NoStderr(),
}); });
}); });
} }
...@@ -149,3 +149,50 @@ class _CrashCommand extends FlutterCommand { ...@@ -149,3 +149,50 @@ class _CrashCommand extends FlutterCommand {
fn3(); fn3();
} }
} }
class _NoStderr extends Stdio {
const _NoStderr();
@override
IOSink get stderr => const _NoopIOSink();
}
class _NoopIOSink implements IOSink {
const _NoopIOSink();
@override
Encoding get encoding => utf8;
@override
set encoding(_) => throw new UnsupportedError('');
@override
void add(_) {}
@override
void write(_) {}
@override
void writeAll(_, [__]) {}
@override
void writeln([_]) {}
@override
void writeCharCode(_) {}
@override
void addError(_, [__]) {}
@override
Future<dynamic> addStream(_) async {}
@override
Future<dynamic> flush() async {}
@override
Future<dynamic> close() async {}
@override
Future<dynamic> get done async {}
}
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