You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A way to log when a property defaults on the default value #69
Hello, the Default implementation is very useful when wanting to create a more resilient application in regards to a highly dynamic backend. The problem is that before when a mandatory value was missing an error is thrown in the debugger or tracked for a production app. Defaulting is great but would make things hard to debug when backend does not send the proper data. Is there a way to log/track when a value defaulted because it was missing in the json or had an incorrect format?
Hey @EfraimB, I am planning to provide one option with Default macro that will make sure default value is only used when value is missing while erroneous data will throw error. Without this option Default will behave as it does currently, default value will be used for both missing and invalid value.
Yeah, but creating custom HelperCoder defeats the purpose of using the Library to skip custom decoding logic. I just want an universal solution which defaults to some values in most of cases the cases so the app doesn't crash / show decoding error but maintain troubleshooting for when it happens by logging errors in an analytics tool.
@EfraimB the purpose of this library is to remove boiler plate needed for common Codable customization, HelperCoder functionality is provided for users to create customizations which are specific to their use-case and not common. Logging is something that is not part of this library, as whatever is universal to you in terms of logging might not be for someone else.
I am open to contribution if you think logging can be implemented in a way to be universally used by all the users of this library. Till then I am moving this issue to discussions so the final approach of the implementation can be discussed by the users of this library.
Activity
soumyamahunt commentedon Mar 18, 2024
Hey @EfraimB, I am planning to provide one option with
Defaultmacro that will make sure default value is only used when value is missing while erroneous data will throw error. Without this optionDefaultwill behave as it does currently, default value will be used for both missing and invalid value.Logging is something I don't plan to add, you can create custom
HelperCoderwith the logging functionality you want, have you looked intoHelperCoderfunctionality provided?https://swiftpackageindex.com/swiftylab/metacodable/main/tutorials/metacodable/helper
https://swiftpackageindex.com/swiftylab/metacodable/main/documentation/metacodable/helpercoder
EfraimB commentedon Mar 19, 2024
Yeah, but creating custom HelperCoder defeats the purpose of using the Library to skip custom decoding logic. I just want an universal solution which defaults to some values in most of cases the cases so the app doesn't crash / show decoding error but maintain troubleshooting for when it happens by logging errors in an analytics tool.
soumyamahunt commentedon Mar 27, 2024
@EfraimB the purpose of this library is to remove boiler plate needed for common
Codablecustomization,HelperCoderfunctionality is provided for users to create customizations which are specific to their use-case and not common. Logging is something that is not part of this library, as whatever is universal to you in terms of logging might not be for someone else.I am open to contribution if you think logging can be implemented in a way to be universally used by all the users of this library. Till then I am moving this issue to discussions so the final approach of the implementation can be discussed by the users of this library.