Improve logging a bit
This commit is contained in:
parent
cf3d5d0169
commit
8a42dddb2c
@ -279,8 +279,13 @@ final class CapServer {
|
||||
// MARK: Counts
|
||||
|
||||
private func images(in folder: URL) throws -> [URL] {
|
||||
try fm.contentsOfDirectory(at: folder, includingPropertiesForKeys: nil)
|
||||
.filter { $0.pathExtension == "jpg" }
|
||||
do {
|
||||
return try fm.contentsOfDirectory(at: folder, includingPropertiesForKeys: nil)
|
||||
.filter { $0.pathExtension == "jpg" }
|
||||
} catch {
|
||||
log("Failed to get image urls for cap \(folder.lastPathComponent): \(error)")
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -306,6 +311,7 @@ final class CapServer {
|
||||
*/
|
||||
func save(image data: Data, for cap: Int) throws {
|
||||
guard caps[cap] != nil else {
|
||||
log("Tried to save image for unknown cap \(cap)")
|
||||
throw CapError.unknownId
|
||||
}
|
||||
var id = 0
|
||||
@ -319,7 +325,12 @@ final class CapServer {
|
||||
} else {
|
||||
try createImageFolder(for: cap)
|
||||
}
|
||||
try data.write(to: capImageUrl)
|
||||
do {
|
||||
try data.write(to: capImageUrl)
|
||||
} catch {
|
||||
log("Failed to write image \(id) for cap \(cap): \(error)")
|
||||
throw CapError.invalidFile
|
||||
}
|
||||
caps[cap]!.count = try count(of: cap)
|
||||
addChangedImageToLog(cap: cap, image: id)
|
||||
log("Added image \(id) for cap \(cap)")
|
||||
|
Loading…
Reference in New Issue
Block a user