Better error for when emoji URL decoding fails

Closes #549
This commit is contained in:
Shadowfacts 2024-11-25 21:20:16 -05:00
parent 51f9f421b8
commit 19c3008c8f
1 changed files with 6 additions and 1 deletions

View File

@ -22,7 +22,12 @@ public struct Emoji: Codable, Sendable {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.shortcode = try container.decode(String.self, forKey: .shortcode)
self.url = try container.decode(WebURL.self, forKey: .url)
do {
self.url = try container.decode(WebURL.self, forKey: .url)
} catch {
let s = try? container.decode(String.self, forKey: .url)
throw DecodingError.dataCorrupted(.init(codingPath: container.codingPath + [CodingKeys.url], debugDescription: "Could not decode URL '\(s ?? "<failed to decode string>")'", underlyingError: error))
}
self.staticURL = try container.decode(WebURL.self, forKey: .staticURL)
self.visibleInPicker = try container.decode(Bool.self, forKey: .visibleInPicker)
self.category = try container.decodeIfPresent(String.self, forKey: .category)