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