Skip to content

Commit be3ae4e

Browse files
Avoid assertion failures in deinitializers
1 parent 24f495b commit be3ae4e

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

Sources/WebDriver/Session.swift

+1-6
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,6 @@ public class Session {
363363
}
364364

365365
deinit {
366-
do { try delete() }
367-
catch let error as ErrorResponse {
368-
assertionFailure("Error in Session.delete: \(error)")
369-
} catch {
370-
assertionFailure("Unexpected error in Session.delete: \(error)")
371-
}
366+
try? delete() // Call `delete` directly to handle errors.
372367
}
373368
}

Sources/WinAppDriver/WinAppDriver.swift

+15-12
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public class WinAppDriver: WebDriver {
1818
public static let defaultStartWaitTime: TimeInterval = 1.0
1919

2020
private let httpWebDriver: HTTPWebDriver
21-
private let processTree: Win32ProcessTree?
21+
private var processTree: Win32ProcessTree?
2222
/// The write end of a pipe that is connected to the child process's stdin.
23-
private let childStdinHandle: HANDLE?
23+
private var childStdinHandle: HANDLE?
2424

2525
private init(
2626
httpWebDriver: HTTPWebDriver,
@@ -115,16 +115,7 @@ public class WinAppDriver: WebDriver {
115115
}
116116

117117
deinit {
118-
if let processTree {
119-
do {
120-
try processTree.terminate(waitTime: TimeInterval.infinity)
121-
} catch {
122-
assertionFailure("WinAppDriver did not terminate within the expected time: \(error).")
123-
}
124-
}
125-
if let childStdinHandle {
126-
CloseHandle(childStdinHandle)
127-
}
118+
try? close() // Call close() directly to handle errors.
128119
}
129120

130121
@discardableResult
@@ -135,4 +126,16 @@ public class WinAppDriver: WebDriver {
135126
public func isInconclusiveInteraction(error: ErrorResponse.Status) -> Bool {
136127
error == .winAppDriver_elementNotInteractable || httpWebDriver.isInconclusiveInteraction(error: error)
137128
}
129+
130+
public func close() throws {
131+
if let childStdinHandle {
132+
CloseHandle(childStdinHandle)
133+
self.childStdinHandle = nil
134+
}
135+
136+
if let processTree {
137+
try processTree.terminate(waitTime: TimeInterval.infinity)
138+
self.processTree = nil
139+
}
140+
}
138141
}

0 commit comments

Comments
 (0)