Skip to content

Commit 978c38f

Browse files
committed
Updated logging
1 parent 8fed1a7 commit 978c38f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Sources/Decoder.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,14 @@ internal struct TLVKeyedDecodingContainer <K: CodingKey> : KeyedDecodingContaine
469469
self.decoder.codingPath.append(key)
470470
defer { self.decoder.codingPath.removeLast() }
471471

472-
return try self.value(for: key)?.value.isEmpty ?? true
472+
self.decoder.log?("Check if nil at path \"\(decoder.codingPath.path)\"")
473+
474+
// check if key exists
475+
guard let item = try self.value(for: key) else {
476+
throw DecodingError.keyNotFound(key, DecodingError.Context(codingPath: self.decoder.codingPath, debugDescription: "No value associated with key \(key.stringValue)."))
477+
}
478+
479+
return item.value.isEmpty
473480
}
474481

475482
func decode(_ type: Bool.Type, forKey key: Key) throws -> Bool {
@@ -590,6 +597,7 @@ internal struct TLVKeyedDecodingContainer <K: CodingKey> : KeyedDecodingContaine
590597

591598
self.decoder.codingPath.append(key)
592599
defer { self.decoder.codingPath.removeLast() }
600+
decoder.log?("Will read value at path \"\(decoder.codingPath.path)\"")
593601
guard let item = try self.value(for: key) else {
594602
throw DecodingError.valueNotFound(type, DecodingError.Context(codingPath: self.decoder.codingPath, debugDescription: "Expected \(type) value but found null instead."))
595603
}
@@ -598,8 +606,6 @@ internal struct TLVKeyedDecodingContainer <K: CodingKey> : KeyedDecodingContaine
598606

599607
/// Access actual value
600608
private func value(for key: Key) throws -> TLVItem? {
601-
602-
decoder.log?("Will read value at path \"\(decoder.codingPath.path)\"")
603609
let typeCode = try self.decoder.typeCode(for: key)
604610
return container.first { $0.type == typeCode }
605611
}

Tests/TLVCodingTests/TLVCodingTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,6 @@ final class TLVCodingTests: XCTestCase {
357357

358358
let data = Data([
359359
0,0,
360-
1,0,
361-
2,0,
362360
3,0
363361
])
364362

0 commit comments

Comments
 (0)