Skip to content

Commit a820ad0

Browse files
authored
Merge pull request #647 from Davarg/a.makushkin/fix-optional-unwrapping
Fixed issue with string force unwrap
2 parents 9d71ce8 + 0564ec8 commit a820ad0

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).map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } ?? ""
81+
return result
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)