From 0168c0525992d1bbe610ba9631155f4e3df17055 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 17 May 2022 10:18:28 -0400 Subject: [PATCH] More detailed error message for decoding hashtag urls --- Pachyderm/Sources/Pachyderm/Model/Hashtag.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Pachyderm/Sources/Pachyderm/Model/Hashtag.swift b/Pachyderm/Sources/Pachyderm/Model/Hashtag.swift index ff61dd36..82ef7ffc 100644 --- a/Pachyderm/Sources/Pachyderm/Model/Hashtag.swift +++ b/Pachyderm/Sources/Pachyderm/Model/Hashtag.swift @@ -26,10 +26,17 @@ public class Hashtag: Codable { let container = try decoder.container(keyedBy: CodingKeys.self) self.name = try container.decode(String.self, forKey: .name) // pixelfed (possibly others) don't fully escape special characters in the hashtag url - if let url = URL(try container.decode(WebURL.self, forKey: .url)) { - self.url = url - } else { - throw DecodingError.dataCorruptedError(forKey: .url, in: container, debugDescription: "unable to convert WebURL to URL") + do { + let webURL = try container.decode(WebURL.self, forKey: .url) + if let url = URL(webURL) { + self.url = url + } else { + let s = try? container.decode(String.self, forKey: .url) + throw DecodingError.dataCorruptedError(forKey: .url, in: container, debugDescription: "unable to convert WebURL \(s?.debugDescription ?? "nil") to URL") + } + } catch { + let s = try? container.decode(String.self, forKey: .url) + throw DecodingError.dataCorruptedError(forKey: .url, in: container, debugDescription: "unable to decode WebURL from \(s?.debugDescription ?? "nil")") } self.history = try container.decodeIfPresent([History].self, forKey: .history) }