Fix error handling for the packaging script (#15351)
This fixes the error handling for the packaging script so that it will properly report a failure exit code when it can't find the executable that it's looking for. Added a test too.
This commit is contained in:
parent
4b56ba17d5
commit
984a24c51b
@ -29,7 +29,7 @@ class ProcessRunnerException implements Exception {
|
|||||||
|
|
||||||
final String message;
|
final String message;
|
||||||
final ProcessResult result;
|
final ProcessResult result;
|
||||||
int get exitCode => result.exitCode ?? -1;
|
int get exitCode => result?.exitCode ?? -1;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
@ -39,7 +39,7 @@ class ProcessRunnerException implements Exception {
|
|||||||
}
|
}
|
||||||
final String stderr = result?.stderr ?? '';
|
final String stderr = result?.stderr ?? '';
|
||||||
if (stderr.isNotEmpty) {
|
if (stderr.isNotEmpty) {
|
||||||
output += ':\n${result.stderr}';
|
output += ':\n$stderr';
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -157,6 +157,10 @@ class ProcessRunner {
|
|||||||
final String message = 'Running "${commandLine.join(' ')}" in ${workingDirectory.path} '
|
final String message = 'Running "${commandLine.join(' ')}" in ${workingDirectory.path} '
|
||||||
'failed with:\n${e.toString()}';
|
'failed with:\n${e.toString()}';
|
||||||
throw new ProcessRunnerException(message);
|
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();
|
final int exitCode = await allComplete();
|
||||||
@ -441,7 +445,7 @@ class ArchivePublisher {
|
|||||||
final String destGsPath = '$gsReleaseFolder/$destinationArchivePath';
|
final String destGsPath = '$gsReleaseFolder/$destinationArchivePath';
|
||||||
await _cloudCopy(outputFile.absolute.path, destGsPath);
|
await _cloudCopy(outputFile.absolute.path, destGsPath);
|
||||||
assert(tempDir.existsSync());
|
assert(tempDir.existsSync());
|
||||||
return _updateMetadata();
|
await _updateMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Null> _updateMetadata() async {
|
Future<Null> _updateMetadata() async {
|
||||||
@ -632,6 +636,9 @@ Future<Null> main(List<String> argList) async {
|
|||||||
} on ProcessRunnerException catch (e) {
|
} on ProcessRunnerException catch (e) {
|
||||||
exitCode = e.exitCode;
|
exitCode = e.exitCode;
|
||||||
message = e.message;
|
message = e.message;
|
||||||
|
} catch (e) {
|
||||||
|
exitCode = -1;
|
||||||
|
message = e.toString();
|
||||||
} finally {
|
} finally {
|
||||||
if (removeTempDir) {
|
if (removeTempDir) {
|
||||||
tempDir.deleteSync(recursive: true);
|
tempDir.deleteSync(recursive: true);
|
||||||
|
@ -17,6 +17,24 @@ import 'fake_process_manager.dart';
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
final String testRef = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
|
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<String> commandLine) async {
|
||||||
|
return processRunner.runProcess(commandLine);
|
||||||
|
})(<String>['this_executable_better_not_exist_2857632534321']),
|
||||||
|
throwsA(const isInstanceOf<ProcessRunnerException>()));
|
||||||
|
try {
|
||||||
|
await processRunner.runProcess(<String>['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 <String>['macos', 'linux', 'windows']) {
|
for (String platformName in <String>['macos', 'linux', 'windows']) {
|
||||||
final FakePlatform platform = new FakePlatform(
|
final FakePlatform platform = new FakePlatform(
|
||||||
operatingSystem: platformName,
|
operatingSystem: platformName,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user