Skip to content

Commit

Permalink
Codable: improved decoding errors (#3153)
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto authored Sep 7, 2023
1 parent 0ea37c5 commit 5527f88
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/FoundationExtensions/Decoder+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ extension ErrorUtils {

static func logDecodingError(_ error: Error, type: Any.Type, data: Data? = nil) {
if let data = data {
Logger.debug(Strings.codable.invalid_data_when_decoding(data))
Logger.debug(Strings.codable.invalid_data_when_decoding(data, type))
}

guard let decodingError = error as? DecodingError else {
Expand Down
6 changes: 3 additions & 3 deletions Sources/Logging/Strings/CodableStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Foundation
// swiftlint:disable identifier_name
enum CodableStrings {

case invalid_data_when_decoding(Data)
case invalid_data_when_decoding(Data, _ type: Any.Type)
case unexpectedValueError(type: Any.Type, value: Any)
case valueNotFoundError(value: Any.Type, context: DecodingError.Context)
case keyNotFoundError(type: Any.Type, key: CodingKey, context: DecodingError.Context)
Expand All @@ -32,9 +32,9 @@ extension CodableStrings: LogMessage {

var description: String {
switch self {
case let .invalid_data_when_decoding(data):
case let .invalid_data_when_decoding(data, type):
let content = String(data: data, encoding: .utf8) ?? ""
return "Encountered error when decoding JSON: \(content)"
return "Encountered error when decoding JSON for '\(type)': \(content)"
case let .unexpectedValueError(type, value):
return "Found unexpected value '\(value)' for type '\(type)'"
case let .valueNotFoundError(value, context):
Expand Down

0 comments on commit 5527f88

Please sign in to comment.