@@ -106,6 +106,9 @@ public enum MatrixCommonErrorCode: String, Error, Codable {
106106 case passwordWeak = " M_WEAK_PASSWORD "
107107 case termsNotSigned = " M_TERMS_NOT_SIGNED "
108108 case invalidPepper = " M_INVALID_PEPPER "
109+
110+ // MSC 3575
111+ case unknownPos = " M_UNKNOWN_POS "
109112}
110113
111114public struct MatrixErrorCode : RawRepresentable , Error , Codable {
@@ -292,7 +295,7 @@ public struct MatrixServerError: Error, Codable {
292295}
293296
294297public extension MatrixServerError {
295- internal enum KnownCodingKeys : String , CodingKey , CaseIterable {
298+ internal enum KnownCodingKeys : String , MatrixKnownCodingKeys {
296299 case errcode
297300 case error
298301
@@ -303,37 +306,24 @@ public extension MatrixServerError {
303306 " completed " ,
304307 ]
305308
306- static func doesNotContain( _ key: DynamicCodingKeys ) -> Bool {
309+ static func doesNotContain( _ key: MatrixDynamicCodingKeys ) -> Bool {
307310 !Self. allCases. map ( \. stringValue) . contains ( key. stringValue) && !Self. extraIgnoreValues
308311 . contains ( key. stringValue)
309312 }
310313 }
311314
312- internal struct DynamicCodingKeys : CodingKey {
313- var stringValue : String
314- init ? ( stringValue: String ) {
315- self . stringValue = stringValue
316- }
317-
318- // not used here, but a protocol requirement
319- var intValue : Int ?
320- init ? ( intValue _: Int ) {
321- nil
322- }
323- }
324-
325315 init ( from decoder: Decoder ) throws {
326316 let container = try decoder. container ( keyedBy: KnownCodingKeys . self)
327317 errcode = try container. decodeIfPresent ( MatrixErrorCode . self, forKey: . errcode) ?? . Unknown
328318 error = try container. decodeIfPresent ( String . self, forKey: . error) ?? " "
329319
330320 extraInfo = [ : ]
331- let extraContainer = try decoder. container ( keyedBy: DynamicCodingKeys . self)
321+ let extraContainer = try decoder. container ( keyedBy: MatrixDynamicCodingKeys . self)
332322
333323 for key in extraContainer. allKeys where KnownCodingKeys . doesNotContain ( key) {
334324 let decoded = try extraContainer. decode (
335325 AnyCodable . self,
336- forKey: DynamicCodingKeys ( stringValue: key. stringValue) !
326+ forKey: . init ( stringValue: key. stringValue) !
337327 )
338328 self . extraInfo [ key. stringValue] = decoded
339329 }
@@ -356,7 +346,7 @@ public extension MatrixServerError {
356346 try container. encode ( errcode, forKey: . errcode)
357347 try container. encode ( error, forKey: . error)
358348
359- var extraContainer = encoder. container ( keyedBy: DynamicCodingKeys . self)
349+ var extraContainer = encoder. container ( keyedBy: MatrixDynamicCodingKeys . self)
360350 for (name, value) in extraInfo {
361351 try extraContainer. encode ( value, forKey: . init( stringValue: name) !)
362352 }
0 commit comments