mirror of
https://github.com/dart-lang/sdk
synced 2024-07-19 20:17:27 +00:00
[ CLI ] Add better logging to the DartDev isolate
Should make debugging unhandled errors in the CLI easier. Related issue: https://github.com/flutter/flutter/issues/106753 Change-Id: I6cfc88a52c0af756c0d7a00fc1a2edcf61b86538 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252464 Reviewed-by: Siva Annamalai <asiva@google.com> Auto-Submit: Ben Konyi <bkonyi@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
parent
206fdf148c
commit
887601b726
|
@ -36,38 +36,48 @@ import 'src/vm_interop_handler.dart';
|
|||
/// This is typically called from bin/, but given the length of the method and
|
||||
/// analytics logic, it has been moved here.
|
||||
Future<void> runDartdev(List<String> args, SendPort? port) async {
|
||||
VmInteropHandler.initialize(port);
|
||||
|
||||
// TODO(sigurdm): Remove when top-level pub is removed.
|
||||
if (args[0] == '__deprecated_pub') {
|
||||
// This is the entry-point supporting the top-level `pub` script.
|
||||
// ignore: deprecated_member_use
|
||||
VmInteropHandler.exit(await deprecatedpubCommand().run(args.skip(1)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.contains('run')) {
|
||||
// These flags have a format that can't be handled by package:args, so while
|
||||
// they are valid flags we'll assume the VM has verified them by this point.
|
||||
args = args
|
||||
.where(
|
||||
(element) => !(element.contains('--observe') ||
|
||||
element.contains('--enable-vm-service') ||
|
||||
element.contains('--devtools')),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
// Finally, call the runner to execute the command; see DartdevRunner.
|
||||
final runner = DartdevRunner(args);
|
||||
int? exitCode = 1;
|
||||
try {
|
||||
exitCode = await runner.run(args);
|
||||
VmInteropHandler.initialize(port);
|
||||
|
||||
// TODO(sigurdm): Remove when top-level pub is removed.
|
||||
if (args[0] == '__deprecated_pub') {
|
||||
// This is the entry-point supporting the top-level `pub` script.
|
||||
// ignore: deprecated_member_use
|
||||
exitCode = await deprecatedpubCommand().run(args.skip(1));
|
||||
} else {
|
||||
if (args.contains('run')) {
|
||||
// These flags have a format that can't be handled by package:args, so while
|
||||
// they are valid flags we'll assume the VM has verified them by this point.
|
||||
args = args
|
||||
.where(
|
||||
(element) => !(element.contains('--observe') ||
|
||||
element.contains('--enable-vm-service') ||
|
||||
element.contains('--devtools')),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
// Finally, call the runner to execute the command; see DartdevRunner.
|
||||
final runner = DartdevRunner(args);
|
||||
exitCode = await runner.run(args);
|
||||
}
|
||||
} on UsageException catch (e) {
|
||||
// TODO(sigurdm): It is unclear when a UsageException gets to here, and
|
||||
// when it is in DartdevRunner.runCommand.
|
||||
io.stderr.writeln('$e');
|
||||
exitCode = 64;
|
||||
} catch (e, st) {
|
||||
// Unexpected error encountered.
|
||||
io.stderr.writeln('An unexpected error was encountered by the Dart CLI.');
|
||||
io.stderr.writeln('Please file an issue at '
|
||||
'https://github.com/dart-lang/sdk/issues/new with the following '
|
||||
'details:\n');
|
||||
io.stderr.writeln("Invocation: 'dart ${args.join(' ')}'");
|
||||
io.stderr.writeln("Exception: '$e'");
|
||||
io.stderr.writeln('Stack Trace:');
|
||||
io.stderr.writeln(st.toString());
|
||||
exitCode = 255;
|
||||
} finally {
|
||||
VmInteropHandler.exit(exitCode);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue