Return exit code 2 on RuntimeError.VMDoesNotExist (#597)

* Return exit code 2 on RuntimeError.VMDoesNotExist

* Upgrade isFileNotFound() do detect underlying errors
This commit is contained in:
Nikolay Edigaryev 2023-09-12 13:56:49 +04:00 committed by GitHub
parent 4bb248e7b4
commit d4d3852745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -34,9 +34,15 @@ class VMStorageHelper {
}
}
extension NSError {
func isFileNotFound() -> Bool {
return self.code == NSFileNoSuchFileError || self.code == NSFileReadNoSuchFileError
}
}
extension Error {
func isFileNotFound() -> Bool {
(self as NSError).code == NSFileReadNoSuchFileError
(self as NSError).isFileNotFound() || (self as NSError).underlyingErrors.contains(where: { $0.isFileNotFound() })
}
}
@ -111,6 +117,8 @@ extension RuntimeError : CustomStringConvertible {
extension RuntimeError : HasExitCode {
var exitCode: Int32 {
switch self {
case .VMDoesNotExist:
return 2
case .VMNotRunning:
return 2
case .VMAlreadyRunning: