From 31635e59d7ca808128c7a2a8fa639b02b52cd760 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Thu, 1 Dec 2022 23:03:21 +0400 Subject: [PATCH] Don't swallow VZVirtualMachine.start() exceptions (#343) * Don't swallow VZVirtualMachine.start() exceptions * Rename task to startTask for clarity * No need to use "self" --- Sources/tart/VM.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sources/tart/VM.swift b/Sources/tart/VM.swift index 0438cd3..a9342be 100644 --- a/Sources/tart/VM.swift +++ b/Sources/tart/VM.swift @@ -219,7 +219,7 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { func run(_ recovery: Bool) async throws { try network.run(sema) - DispatchQueue.main.sync { + let startTask = DispatchQueue.main.sync { Task { if #available(macOS 13, *) { // new API introduced in Ventura @@ -233,7 +233,12 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { } } - await withTaskCancellationHandler(operation: { + try await withTaskCancellationHandler(operation: { + // Await on VZVirtualMachine.start() result + _ = try await startTask.value + + // Wait for the VM to finish running + // or for the exit condition sema.wait() }, onCancel: { sema.signal()