tart delete: return human-friendly error when local VM doesn't exist (#910)

This commit is contained in:
Nikolay Edigaryev 2024-09-26 14:45:14 +04:00 committed by GitHub
parent b9f24a40c1
commit dbf711a6c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -11,7 +11,7 @@ class PIDLock {
if fd == -1 {
let details = Errno(rawValue: CInt(errno))
throw RuntimeError.PIDLockFailed("failed to open lock file \(url): \(details)")
throw RuntimeError.PIDLockMissing("failed to open lock file \(url): \(details)")
}
}

View File

@ -24,6 +24,8 @@ class VMStorageHelper {
private static func missingVMWrap<R: Any>(_ name: String, closure: () throws -> R) throws -> R {
do {
return try closure()
} catch RuntimeError.PIDLockMissing {
throw RuntimeError.VMDoesNotExist(name: name)
} catch {
if error.isFileNotFound() {
throw RuntimeError.VMDoesNotExist(name: name)
@ -59,6 +61,7 @@ enum RuntimeError : Error {
case InvalidDiskSize(_ message: String)
case FailedToUpdateAccessDate(_ message: String)
case PIDLockFailed(_ message: String)
case PIDLockMissing(_ message: String)
case FailedToParseRemoteName(_ message: String)
case VMTerminationFailed(_ message: String)
case ImproperlyFormattedHost(_ host: String, _ hint: String)
@ -105,6 +108,8 @@ extension RuntimeError : CustomStringConvertible {
return message
case .PIDLockFailed(let message):
return message
case .PIDLockMissing(let message):
return message
case .FailedToParseRemoteName(let cause):
return "failed to parse remote name: \(cause)"
case .VMTerminationFailed(let message):