Unverified Commit 071d4eb2 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

explicitly catch ArgumentError, and add tests (#52757)

parent a4d30c16
...@@ -542,6 +542,9 @@ class _DefaultProcessUtils implements ProcessUtils { ...@@ -542,6 +542,9 @@ class _DefaultProcessUtils implements ProcessUtils {
} on Exception catch (error) { } on Exception catch (error) {
_logger.printTrace('$cli failed with $error'); _logger.printTrace('$cli failed with $error');
return false; return false;
} on ArgumentError catch (error) {
_logger.printTrace('$cli failed with $error');
return false;
} }
} }
...@@ -556,6 +559,9 @@ class _DefaultProcessUtils implements ProcessUtils { ...@@ -556,6 +559,9 @@ class _DefaultProcessUtils implements ProcessUtils {
} on Exception catch (error) { } on Exception catch (error) {
_logger.printTrace('$cli failed with $error'); _logger.printTrace('$cli failed with $error');
return false; return false;
} on ArgumentError catch (error) {
_logger.printTrace('$cli failed with $error');
return false;
} }
} }
......
...@@ -360,6 +360,20 @@ void main() { ...@@ -360,6 +360,20 @@ void main() {
); );
expect(processUtils.exitsHappySync(<String>['boohoo']), isFalse); expect(processUtils.exitsHappySync(<String>['boohoo']), isFalse);
}); });
testWithoutContext('catches Exception and returns false', () {
when(mockProcessManager.runSync(<String>['boohoo'])).thenThrow(
const ProcessException('Process failed', <String>[]),
);
expect(processUtils.exitsHappySync(<String>['boohoo']), isFalse);
});
testWithoutContext('catches ArgumentError and returns false', () {
when(mockProcessManager.runSync(<String>['nonesuch'])).thenThrow(
ArgumentError('Invalid argument(s): Cannot find executable for nonesuch')
);
expect(processUtils.exitsHappySync(<String>['nonesuch']), isFalse);
});
}); });
group('exitsHappy', () { group('exitsHappy', () {
...@@ -387,6 +401,20 @@ void main() { ...@@ -387,6 +401,20 @@ void main() {
}); });
expect(await processUtils.exitsHappy(<String>['boohoo']), isFalse); expect(await processUtils.exitsHappy(<String>['boohoo']), isFalse);
}); });
testWithoutContext('catches Exception and returns false', () async {
when(mockProcessManager.run(<String>['boohoo'])).thenThrow(
const ProcessException('Process failed', <String>[]),
);
expect(await processUtils.exitsHappy(<String>['boohoo']), isFalse);
});
testWithoutContext('catches ArgumentError and returns false', () async {
when(mockProcessManager.run(<String>['nonesuch'])).thenThrow(
ArgumentError('Invalid argument(s): Cannot find executable for nonesuch'),
);
expect(await processUtils.exitsHappy(<String>['nonesuch']), isFalse);
});
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment