Skip to content

Commit 44a0f9b

Browse files
committed
Fixed issue with string force unwrap
1 parent 0c28968 commit 44a0f9b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/DangerShellExecutor/ShellExecutor.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public struct ShellExecutor: ShellExecuting {
7777

7878
task.waitUntilExit()
7979

80-
return String(data: data, encoding: .utf8)!.trimmingCharacters(in: .whitespacesAndNewlines)
80+
let result = String(data: data, encoding: .utf8) ?? ""
81+
return result.trimmingCharacters(in: .whitespacesAndNewlines)
8182
} catch {
8283
return error.localizedDescription
8384
}
@@ -109,7 +110,7 @@ public struct ShellExecutor: ShellExecuting {
109110
outputQueue.async(group: group, qos: .userInitiated) {
110111
// Pull out the STDOUT as a string because we'll need that regardless
111112
let stdoutData = stdout.fileHandleForReading.readDataToEndOfFile()
112-
stdoutString = String(data: stdoutData, encoding: .utf8)!
113+
stdoutString = String(data: stdoutData, encoding: .utf8) ?? ""
113114
}
114115

115116
outputQueue.async(group: group, qos: .userInitiated) {

0 commit comments

Comments
 (0)