Skip to content

A way to log when a property defaults on the default value #69

Description

@EfraimB

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?

Activity

  1. soumyamahunt commented on Mar 18, 2024

    @soumyamahunt
    Contributor

    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.

    Logging is something I don't plan to add, you can create custom HelperCoder with the logging functionality you want, have you looked into HelperCoder functionality provided?
    https://swiftpackageindex.com/swiftylab/metacodable/main/tutorials/metacodable/helper
    https://swiftpackageindex.com/swiftylab/metacodable/main/documentation/metacodable/helpercoder

  2. EfraimB commented on Mar 19, 2024

    @EfraimB
    Author

    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.

  3. soumyamahunt commented on Mar 27, 2024

    @soumyamahunt
    Contributor

    @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.

  4. locked and limited conversation to collaborators on Mar 27, 2024
  5. converted this issue into a discussion #73 on Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions