diff --git a/dev/bots/prepare_package.dart b/dev/bots/prepare_package.dart index 5f12782e42..0f1c0556ce 100644 --- a/dev/bots/prepare_package.dart +++ b/dev/bots/prepare_package.dart @@ -29,7 +29,7 @@ class ProcessRunnerException implements Exception { final String message; final ProcessResult result; - int get exitCode => result.exitCode ?? -1; + int get exitCode => result?.exitCode ?? -1; @override String toString() { @@ -39,7 +39,7 @@ class ProcessRunnerException implements Exception { } final String stderr = result?.stderr ?? ''; if (stderr.isNotEmpty) { - output += ':\n${result.stderr}'; + output += ':\n$stderr'; } return output; } @@ -157,6 +157,10 @@ class ProcessRunner { final String message = 'Running "${commandLine.join(' ')}" in ${workingDirectory.path} ' 'failed with:\n${e.toString()}'; throw new ProcessRunnerException(message); + } on ArgumentError catch (e) { + final String message = 'Running "${commandLine.join(' ')}" in ${workingDirectory.path} ' + 'failed with:\n${e.toString()}'; + throw new ProcessRunnerException(message); } final int exitCode = await allComplete(); @@ -441,7 +445,7 @@ class ArchivePublisher { final String destGsPath = '$gsReleaseFolder/$destinationArchivePath'; await _cloudCopy(outputFile.absolute.path, destGsPath); assert(tempDir.existsSync()); - return _updateMetadata(); + await _updateMetadata(); } Future _updateMetadata() async { @@ -632,6 +636,9 @@ Future main(List argList) async { } on ProcessRunnerException catch (e) { exitCode = e.exitCode; message = e.message; + } catch (e) { + exitCode = -1; + message = e.toString(); } finally { if (removeTempDir) { tempDir.deleteSync(recursive: true); diff --git a/dev/bots/test/prepare_package_test.dart b/dev/bots/test/prepare_package_test.dart index f9c18fe97d..c460e7ba7f 100644 --- a/dev/bots/test/prepare_package_test.dart +++ b/dev/bots/test/prepare_package_test.dart @@ -17,6 +17,24 @@ import 'fake_process_manager.dart'; void main() { final String testRef = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef'; + test('Throws on missing executable', () async { + // Uses a *real* process manager, since we want to know what happens if + // it can't find an executable. + final ProcessRunner processRunner = new ProcessRunner(subprocessOutput: false); + expect( + expectAsync1((List commandLine) async { + return processRunner.runProcess(commandLine); + })(['this_executable_better_not_exist_2857632534321']), + throwsA(const isInstanceOf())); + try { + await processRunner.runProcess(['this_executable_better_not_exist_2857632534321']); + } on ProcessRunnerException catch (e) { + expect( + e.message, + contains('Invalid argument(s): Cannot find executable for this_executable_better_not_exist_2857632534321.'), + ); + } + }); for (String platformName in ['macos', 'linux', 'windows']) { final FakePlatform platform = new FakePlatform( operatingSystem: platformName,