Improve logging
This commit is contained in:
parent
464f87fdb5
commit
d596a9d790
@ -235,12 +235,20 @@ final class CapServer {
|
|||||||
log("Failed to get image urls for cap \(cap.id)")
|
log("Failed to get image urls for cap \(cap.id)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if images.count != cap.count {
|
||||||
|
log("\(images.count) instead of \(cap.count) images for cap \(cap.id)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get list of existing images
|
||||||
var sorted: [(id: Int, url: URL)] = images.compactMap {
|
var sorted: [(id: Int, url: URL)] = images.compactMap {
|
||||||
guard let id = Int($0.deletingPathExtension().lastPathComponent.components(separatedBy: "-").last!) else {
|
guard let id = Int($0.deletingPathExtension().lastPathComponent.components(separatedBy: "-").last!) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return (id, $0)
|
return (id, $0)
|
||||||
}.sorted { $0.id < $1.id }
|
}.sorted { $0.id < $1.id }
|
||||||
|
|
||||||
|
// Check that all images are available
|
||||||
for version in 0..<images.count {
|
for version in 0..<images.count {
|
||||||
guard version != sorted[version].id else {
|
guard version != sorted[version].id else {
|
||||||
continue
|
continue
|
||||||
@ -249,6 +257,7 @@ final class CapServer {
|
|||||||
let newUrl = imageUrl(of: cap.id, version: version)
|
let newUrl = imageUrl(of: cap.id, version: version)
|
||||||
do {
|
do {
|
||||||
try fm.moveItem(at: lastImage.url, to: newUrl)
|
try fm.moveItem(at: lastImage.url, to: newUrl)
|
||||||
|
log("Moved image \(lastImage.id) to \(version) for cap \(cap.id)")
|
||||||
} catch {
|
} catch {
|
||||||
log("Failed to move file \(lastImage.url.path) to \(newUrl.path): \(error)")
|
log("Failed to move file \(lastImage.url.path) to \(newUrl.path): \(error)")
|
||||||
return
|
return
|
||||||
|
@ -458,12 +458,12 @@ final class ClassifierCreator {
|
|||||||
do {
|
do {
|
||||||
(data, response) = try await URLSession.shared.data(for: request)
|
(data, response) = try await URLSession.shared.data(for: request)
|
||||||
} catch {
|
} catch {
|
||||||
print("[ERROR] Request failed: \(error)")
|
print("[ERROR] Request to \(request.url!.absoluteString) failed: \(error)")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
let code = (response as! HTTPURLResponse).statusCode
|
let code = (response as! HTTPURLResponse).statusCode
|
||||||
guard code == 200 else {
|
guard code == 200 else {
|
||||||
print("[ERROR] Invalid response \(code)")
|
print("[ERROR] Request to \(request.url!.absoluteString): Invalid response \(code)")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
Loading…
Reference in New Issue
Block a user