fix: handling process exit on abort (#2238)
This commit is contained in:
@@ -16,6 +16,7 @@ import 'package:shorebird_cli/src/shorebird_env.dart';
|
||||
import 'package:shorebird_cli/src/shorebird_flutter.dart';
|
||||
import 'package:shorebird_cli/src/shorebird_process.dart';
|
||||
import 'package:shorebird_cli/src/shorebird_version.dart';
|
||||
import 'package:shorebird_cli/src/third_party/flutter_tools/lib/flutter_tools.dart';
|
||||
import 'package:shorebird_cli/src/version.dart';
|
||||
|
||||
const executableName = 'shorebird';
|
||||
@@ -197,6 +198,8 @@ Engine • revision ${shorebirdEnv.shorebirdEngineRevision}''');
|
||||
} else {
|
||||
try {
|
||||
exitCode = await super.runCommand(topLevelResults);
|
||||
} on ProcessExit catch (error) {
|
||||
exitCode = error.exitCode;
|
||||
} catch (error, stackTrace) {
|
||||
logger
|
||||
..err('$error')
|
||||
@@ -205,7 +208,7 @@ Engine • revision ${shorebirdEnv.shorebirdEngineRevision}''');
|
||||
}
|
||||
}
|
||||
|
||||
if (exitCode == ExitCode.software.code && logger.level != Level.verbose) {
|
||||
if (exitCode != ExitCode.success.code && logger.level != Level.verbose) {
|
||||
final fileAnIssue = link(
|
||||
uri: Uri.parse(
|
||||
'https://github.com/shorebirdtech/shorebird/issues/new/choose',
|
||||
|
||||
@@ -8,9 +8,11 @@ import 'package:scoped_deps/scoped_deps.dart';
|
||||
import 'package:shorebird_cli/src/logger.dart' hide logger;
|
||||
import 'package:shorebird_cli/src/platform.dart';
|
||||
import 'package:shorebird_cli/src/shorebird_cli_command_runner.dart';
|
||||
import 'package:shorebird_cli/src/shorebird_command.dart';
|
||||
import 'package:shorebird_cli/src/shorebird_env.dart';
|
||||
import 'package:shorebird_cli/src/shorebird_flutter.dart';
|
||||
import 'package:shorebird_cli/src/shorebird_version.dart';
|
||||
import 'package:shorebird_cli/src/third_party/flutter_tools/lib/flutter_tools.dart';
|
||||
import 'package:shorebird_cli/src/version.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
@@ -68,6 +70,31 @@ void main() {
|
||||
commandRunner = runWithOverrides(ShorebirdCliCommandRunner.new);
|
||||
});
|
||||
|
||||
group('handles ProcessExit', () {
|
||||
test('does nothing when exit code is 0', () async {
|
||||
commandRunner.addCommand(_TestCommand(ExitCode.success));
|
||||
final result = await runWithOverrides(
|
||||
() => commandRunner.run(['test']),
|
||||
);
|
||||
expect(result, equals(ExitCode.success.code));
|
||||
});
|
||||
|
||||
test('exits with the correct code', () async {
|
||||
commandRunner.addCommand(_TestCommand(ExitCode.unavailable));
|
||||
final result = await runWithOverrides(
|
||||
() => commandRunner.run(['test']),
|
||||
);
|
||||
expect(result, equals(ExitCode.unavailable.code));
|
||||
verify(
|
||||
() => logger.info(
|
||||
any(
|
||||
that: contains('''If you aren't sure why this command failed'''),
|
||||
),
|
||||
),
|
||||
).called(1);
|
||||
});
|
||||
});
|
||||
|
||||
test('handles FormatException', () async {
|
||||
const exception = FormatException('oops!');
|
||||
var isFirstInvocation = true;
|
||||
@@ -386,3 +413,20 @@ Engine • revision $shorebirdEngineRevision''',
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class _TestCommand extends ShorebirdCommand {
|
||||
_TestCommand(this.exitCode);
|
||||
|
||||
final ExitCode exitCode;
|
||||
|
||||
@override
|
||||
String get name => 'test';
|
||||
|
||||
@override
|
||||
String get description => 'Test command';
|
||||
|
||||
@override
|
||||
Future<int> run() async {
|
||||
throw ProcessExit(exitCode.code);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user