Skip to content

Instantly share code, notes, and snippets.

@hsleedevelop
Created October 20, 2021 08:25
Show Gist options
  • Save hsleedevelop/1ec71cd52310df639304e17578bedad6 to your computer and use it in GitHub Desktop.
Save hsleedevelop/1ec71cd52310df639304e17578bedad6 to your computer and use it in GitHub Desktop.
Codable debugging
do {
let output = try decoder.decode(FlanetNotification.self, from: data)
App.ui.alert(message:"parsed!!!", callback: nil)
} catch DecodingError.dataCorrupted(let context) {
App.ui.alert(message: context.debugDescription, callback: nil)
} catch DecodingError.keyNotFound(let key, let context) {
App.ui.alert(title: "Key '\(key)' not found:", message: context.debugDescription, callback: nil)
App.ui.alert(title: "codingPath: \(context.codingPath)", message: context.debugDescription, callback: nil)
} catch DecodingError.valueNotFound(let value, let context) {
print("Value '\(value)' not found:", context.debugDescription)
print("codingPath:", context.codingPath)
App.ui.alert(title: "Value '\(value)' not found:", message: context.debugDescription, callback: nil)
App.ui.alert(title: "codingPath: \(context.codingPath)", message: context.debugDescription, callback: nil)
} catch DecodingError.typeMismatch(let type, let context) {
print("Type '\(type)' mismatch:", context.debugDescription)
print("codingPath:", context.codingPath)
App.ui.alert(title: "Type '\(type)' mismatch:", message: context.debugDescription, callback: nil)
App.ui.alert(title: "codingPath: \(context.codingPath)", message: context.debugDescription, callback: nil)
} catch {
print("error: ", error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment