Skip to content

Commit 17755fa

Browse files
committed
Continue to write other files when a certain file is corrupted.
1 parent fbf596d commit 17755fa

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

Sources/FigmaExport/Output/FileWriter.swift

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
1-
import Foundation
21
import FigmaExportCore
2+
import Foundation
3+
import Logging
34
#if os(Linux)
45
import FoundationXML
56
#endif
67

78
final class FileWriter {
8-
99
private let fileManager: FileManager
10-
10+
private let logger = Logger(label: "com.redmadrobot.figma-export.file-writer")
11+
1112
init(fileManager: FileManager = .default) {
1213
self.fileManager = fileManager
1314
}
14-
15+
1516
func write(files: [FileContents]) throws {
1617
try files.forEach { file in
1718
let directoryURL = URL(fileURLWithPath: file.destination.directory.path)
1819
try fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil)
19-
20+
2021
let fileURL = URL(fileURLWithPath: file.destination.url.path)
21-
if let data = file.data {
22-
try data.write(to: fileURL, options: .atomic)
23-
} else if let localFileURL = file.dataFile {
24-
_ = try fileManager.replaceItemAt(fileURL, withItemAt: localFileURL)
25-
} else {
26-
fatalError("FileContents.data is nil. Use FileDownloader to download contents of the file.")
22+
do {
23+
if let data = file.data {
24+
try data.write(to: fileURL, options: .atomic)
25+
} else if let localFileURL = file.dataFile {
26+
_ = try fileManager.replaceItemAt(fileURL, withItemAt: localFileURL)
27+
} else {
28+
fatalError("FileContents.data is nil. Use FileDownloader to download contents of the file.")
29+
}
30+
} catch let e {
31+
logger.error("\(e.localizedDescription)")
2732
}
2833
}
2934
}
30-
35+
3136
func write(xmlFile: XMLDocument, directory: URL) throws {
3237
let fileURL = URL(fileURLWithPath: directory.path)
3338
let options: XMLNode.Options = [.nodePrettyPrint, .nodeCompactEmptyElement]

0 commit comments

Comments
 (0)