Codable: debug log entire JSON when decoding fails#2864
Merged
Conversation
This is a simple example, but on a larger JSON it becomes easier for us to debug decoding the entire JSON rather than seeing only the part that failed:
```
[codable] DEBUG: ℹ️ Encountered error when decoding JSON: {"e": "e3"}
[codable] ERROR: 😿‼️ Couldn't decode data from json, it was corrupted: Context(codingPath: [CodingKeys(stringValue: "e", intValue: nil)], debugDescription: "Cannot initialize E from invalid String value e3", underlyingError: nil)
```
Contributor
Author
|
I love these little QoL improvements. I was trying to figure out what was wrong in a test, this helped. |
tonidero
approved these changes
Jul 24, 2023
tonidero
left a comment
Contributor
There was a problem hiding this comment.
Left a comment... But can see it working either way
| static func logDecodingError(_ error: Error, type: Any.Type) { | ||
| static func logDecodingError(_ error: Error, type: Any.Type, data: Data? = nil) { | ||
| if let data = data { | ||
| Logger.debug(Strings.codable.invalid_data_when_decoding(data)) |
Contributor
There was a problem hiding this comment.
Hmm so this will be a separate log. I wonder if it should be part of the error log below...
Contributor
Author
There was a problem hiding this comment.
I did it this way for 2 reasons, let me know what you think:
- The implementation of this method uses like 5 different strings so I'd have to modify all of them
- The JSON might contain sensitive data, so we might not want the whole thing to be in the console. In release builds,
debuglogs aren't enabled by default, therefore eliminating this.
NachoSoto
added a commit
that referenced
this pull request
Jul 26, 2023
**This is an automatic release.** _This release is compatible with Xcode 15 beta 5 and visionOS beta 2_ ### Bugfixes * `xrOS`: fixed `SubscriptionStoreView` for visionOS beta 2 (#2884) via Josh Holtz (@joshdholtz) ### Performance Improvements * `Perf`: update `CustomerInfo` cache before anything else (#2865) via NachoSoto (@NachoSoto) ### Other Changes * `SimpleApp`: added support for localization (#2880) via NachoSoto (@NachoSoto) * `TestStoreProduct`: made available on release builds (#2861) via NachoSoto (@NachoSoto) * `Tests`: increased default logger capacity (#2870) via NachoSoto (@NachoSoto) * `CustomEntitlementComputation`: removed `invalidateCustomerInfoCache` (#2866) via NachoSoto (@NachoSoto) * `SimpleApp`: updates for TestFlight compatibility (#2862) via NachoSoto (@NachoSoto) * `BasePurchasesTests`: consolidate to only initialize one `DeviceCache` (#2863) via NachoSoto (@NachoSoto) * `Codable`: debug log entire JSON when decoding fails (#2864) via NachoSoto (@NachoSoto) * `IntegrationTests`: replaced `Purchases.shared` with a `throw`ing property (#2867) via NachoSoto (@NachoSoto) * `NetworkError`: 2 new tests to ensure underlying error is included in description (#2843) via NachoSoto (@NachoSoto) * Add SPM `Package.resolved` for Xcode Cloud (#2844) via NachoSoto (@NachoSoto) * `CustomEntitlementComputation`: added integration test for cancellations (#2849) via NachoSoto (@NachoSoto) * `CustomEntitlementComputation`: removed `syncPurchases`/`restorePurchases` (#2854) via NachoSoto (@NachoSoto) --------- Co-authored-by: NachoSoto <ignaciosoto90@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a simple example, but on a larger JSON it becomes easier for us to debug decoding the entire JSON rather than seeing only the part that failed: