From 887601b726066896137e3f6764653b0fe22d4886 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Mon, 25 Jul 2022 14:44:59 +0000 Subject: [PATCH] [ 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 Auto-Submit: Ben Konyi Commit-Queue: Ben Konyi --- pkg/dartdev/lib/dartdev.dart | 60 +++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/pkg/dartdev/lib/dartdev.dart b/pkg/dartdev/lib/dartdev.dart index 11ddd0634c0..f6f37dd4702 100644 --- a/pkg/dartdev/lib/dartdev.dart +++ b/pkg/dartdev/lib/dartdev.dart @@ -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 runDartdev(List 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); }