Skip to content

Commit

Permalink
Don't abort when persiting is successful and fatalError on persistenc…
Browse files Browse the repository at this point in the history
…e issues
  • Loading branch information
mr-v committed Dec 7, 2017
1 parent 890067e commit bedabc3
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions DVR/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,14 @@ open class Session: URLSession {
}

private func persist(_ interactions: [Interaction]) {
defer {
abort()
}

// Create directory
let outputDirectory = (self.outputDirectory as NSString).expandingTildeInPath
let fileManager = FileManager.default
if !fileManager.fileExists(atPath: outputDirectory) {
do {
try fileManager.createDirectory(atPath: outputDirectory, withIntermediateDirectories: true, attributes: nil)
} catch {
print("[DVR] Failed to create cassettes directory.")
fatalError("[DVR] Failed to create cassettes directory.")
}
}

Expand All @@ -206,20 +202,18 @@ open class Session: URLSession {

// Add trailing new line
guard var string = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else {
print("[DVR] Failed to persist cassette.")
return
fatalError("[DVR] Failed to persist cassette.")
}
string = string.appending("\n") as NSString

if let data = string.data(using: String.Encoding.utf8.rawValue) {
try? data.write(to: URL(fileURLWithPath: outputPath), options: [.atomic])
print("[DVR] Persisted cassette at \(outputPath). Please add this file to your test target")
return
print("ℹ️ [DVR] Persisted cassette at \(outputPath). Please add this file to your test target")
} else {
fatalError("[DVR] Failed to persist cassette.")
}

print("[DVR] Failed to persist cassette.")
} catch {
print("[DVR] Failed to persist cassette.")
fatalError("[DVR] Failed to persist cassette.")
}
}

Expand Down

0 comments on commit bedabc3

Please sign in to comment.