diff --git a/Sources/tart/VMStorageHelper.swift b/Sources/tart/VMStorageHelper.swift index 89a47ad..1e523ae 100644 --- a/Sources/tart/VMStorageHelper.swift +++ b/Sources/tart/VMStorageHelper.swift @@ -38,7 +38,8 @@ class VMStorageHelper { extension NSError { func isFileNotFound() -> Bool { - return self.code == NSFileNoSuchFileError || self.code == NSFileReadNoSuchFileError + return self.domain == NSCocoaErrorDomain && + (self.code == NSFileNoSuchFileError || self.code == NSFileReadNoSuchFileError) } } diff --git a/Tests/TartTests/CommandBehaviorTests.swift b/Tests/TartTests/CommandBehaviorTests.swift index c579b0b..b8453c0 100644 --- a/Tests/TartTests/CommandBehaviorTests.swift +++ b/Tests/TartTests/CommandBehaviorTests.swift @@ -116,6 +116,12 @@ final class CommandBehaviorTests: XCTestCase { } } + func testFileNotFoundRequiresCocoaErrorDomain() { + XCTAssertTrue(NSError(domain: NSCocoaErrorDomain, code: NSFileNoSuchFileError).isFileNotFound()) + XCTAssertTrue(NSError(domain: NSCocoaErrorDomain, code: NSFileReadNoSuchFileError).isFileNotFound()) + XCTAssertFalse(RuntimeError.VMIsRunning("running").isFileNotFound()) + } + func testSetDiskRejectsStackedVMBeforeSavingConfig() async throws { try await withTemporaryTartHome { let vmDir = try VMStorageLocal().create("stacked")