Skip to content

Commit abb3304

Browse files
committed
Improve error handling
1 parent d21a8f7 commit abb3304

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Sources/MusadoraKit/Extension/CommonImageProcessing.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,12 @@ struct CommonImageProcessing {
170170

171171
for clusterIndex in 0..<clusters.count {
172172
let cluster = clusters[clusterIndex]
173-
if cluster.points.isEmpty { continue }
173+
guard !cluster.points.isEmpty else { continue }
174174
let sum = cluster.points.reduce(PixelData(red: 0, green: 0, blue: 0)) { result, pixel -> PixelData in
175175
return PixelData(red: result.red + pixel.red, green: result.green + pixel.green, blue: result.blue + pixel.blue)
176176
}
177177
let count = Double(cluster.points.count)
178+
guard count > 0 else { continue }
178179
clusters[clusterIndex].center = PixelData(red: sum.red / count, green: sum.green / count, blue: sum.blue / count)
179180
}
180181
}

Sources/MusadoraKit/Extension/UIColor.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ extension UIColor {
2424
return "#000000"
2525
}
2626

27+
guard components.count > 2 else {
28+
return "#000000"
29+
}
30+
2731
let r = Int(components[0] * 255.0)
2832
let g = Int(components[1] * 255.0)
2933
let b = Int(components[2] * 255.0)

Sources/MusadoraKit/Views/AnimatedArtworkView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import MusicKit
22
import SwiftUI
3+
import os.log
34

45
/// A view that displays an animated artwork with a dynamic mesh gradient background.
56
///
@@ -118,7 +119,7 @@ public struct AnimatedArtworkView: View {
118119
self.dominantColors = colors
119120
}
120121
} catch {
121-
// Silently fail - colors will remain empty or previous values
122+
os_log("Failed to extract colors from artwork: %@", log: OSLog.default, type: .error, error.localizedDescription)
122123
}
123124
}
124125

0 commit comments

Comments
 (0)