From 5be9945f7ab31f46231f59c09d7556fe64fb6f21 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 25 Nov 2024 21:20:16 -0500 Subject: [PATCH] Better error for when emoji URL decoding fails Closes #549 --- Packages/Pachyderm/Sources/Pachyderm/Model/Emoji.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Packages/Pachyderm/Sources/Pachyderm/Model/Emoji.swift b/Packages/Pachyderm/Sources/Pachyderm/Model/Emoji.swift index da263257..8a11f139 100644 --- a/Packages/Pachyderm/Sources/Pachyderm/Model/Emoji.swift +++ b/Packages/Pachyderm/Sources/Pachyderm/Model/Emoji.swift @@ -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 ?? "")'", 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)