From 125c6a7d677696455db942254e113cc8850953dc Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 28 Apr 2019 21:31:53 +0200 Subject: [PATCH 1/2] Fix encoding of external map in preset The effect of this is that refreshed infrastructures were not remembered. --- Passepartout/Sources/Services/InfrastructurePreset.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Passepartout/Sources/Services/InfrastructurePreset.swift b/Passepartout/Sources/Services/InfrastructurePreset.swift index 14529b66..d502ac7f 100644 --- a/Passepartout/Sources/Services/InfrastructurePreset.swift +++ b/Passepartout/Sources/Services/InfrastructurePreset.swift @@ -205,7 +205,13 @@ public struct InfrastructurePreset: Codable { try container.encode(id, forKey: .id) try container.encode(name, forKey: .name) try container.encode(comment, forKey: .comment) - try container.encodeIfPresent(external, forKey: .external) + if let external = external { + var rawExternal: [String: String] = [:] + for entry in external { + rawExternal[entry.key.rawValue] = entry.value + } + try container.encodeIfPresent(rawExternal, forKey: .external) + } var cfgContainer = container.nestedContainer(keyedBy: ConfigurationKeys.self, forKey: .configuration) try cfgContainer.encode(configuration.sessionConfiguration.cipher, forKey: .cipher) From b714f8acd9deefa406672a2046f18d8a41bba5dc Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 28 Apr 2019 21:33:08 +0200 Subject: [PATCH 2/2] Log cached infra JSON when unable to parse --- Passepartout/Sources/Services/InfrastructureFactory.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Passepartout/Sources/Services/InfrastructureFactory.swift b/Passepartout/Sources/Services/InfrastructureFactory.swift index 54aee817..197ba146 100644 --- a/Passepartout/Sources/Services/InfrastructureFactory.swift +++ b/Passepartout/Sources/Services/InfrastructureFactory.swift @@ -106,7 +106,12 @@ public class InfrastructureFactory { guard let data = try? Data(contentsOf: entry) else { continue } - guard let infra = try? decoder.decode(Infrastructure.self, from: data) else { + let infra: Infrastructure + do { + infra = try decoder.decode(Infrastructure.self, from: data) + } catch let e { + log.warning("Unable to load infrastructure \(entry.lastPathComponent): \(e)") + log.warning("\(String(data: data, encoding: .utf8)!)") continue }