Skip to content

Commit 07ee7df

Browse files
committed
feat: add OptionalPolymorphicValue, LossyOptionalPolymorphicValue outcome logic
1 parent ea39186 commit 07ee7df

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

Sources/KarrotCodableKit/PolymorphicCodable/LossyOptionalPolymorphicValue.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ extension LossyOptionalPolymorphicValue: Decodable {
6464
do {
6565
self.wrappedValue = try PolymorphicType.decode(from: decoder)
6666
self.outcome = .decodedSuccessfully
67+
68+
} catch DecodingError.keyNotFound {
69+
self.wrappedValue = nil
70+
self.outcome = .keyNotFound
71+
72+
} catch DecodingError.valueNotFound(let rawType, _) where rawType == PolymorphicType.ExpectedType.self {
73+
self.wrappedValue = nil
74+
self.outcome = .valueWasNil
75+
6776
} catch {
6877
#if DEBUG
6978
// Report error to resilient decoding error reporter

Sources/KarrotCodableKit/PolymorphicCodable/OptionalPolymorphicValue.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ extension OptionalPolymorphicValue: Decodable {
6161
do {
6262
self.wrappedValue = try PolymorphicType.decode(from: decoder)
6363
self.outcome = .decodedSuccessfully
64+
65+
} catch DecodingError.keyNotFound {
66+
self.wrappedValue = nil
67+
self.outcome = .keyNotFound
68+
69+
} catch DecodingError.valueNotFound(let rawType, _) where rawType == PolymorphicType.ExpectedType.self {
70+
self.wrappedValue = nil
71+
self.outcome = .valueWasNil
72+
6473
} catch {
6574
// OptionalPolymorphicValue throws errors instead of recovering
6675
throw error

0 commit comments

Comments
 (0)