Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TOML difference #186

Closed
chshersh opened this issue Mar 5, 2019 · 8 comments · Fixed by #363
Closed

Implement TOML difference #186

chshersh opened this issue Mar 5, 2019 · 8 comments · Fixed by #363
Assignees
Labels
λ-safe Type safety, validation

Comments

@chshersh
Copy link
Contributor

chshersh commented Mar 5, 2019

Currently if you implement Codec for file that contains more fields that you need, tomland will use only those fields that you specified. However, sometimes it's desired to tell about redundant or unused fields. In JSON it is completely okay to ignore some fields, but in TOML static configuration having some fields in the config may lead to frustration in the future. It would be nice to have some way of telling which fields were not used.

@willbasky
Copy link
Collaborator

Should it be cli command or stderr message after decoding?

@chshersh
Copy link
Contributor Author

chshersh commented Oct 9, 2019

@willbasky Under one issue I proposed the following data type as a result of decoding TOML:

data Result a
    = Failure String
    | Warning [DecodeWarning] a
    | Success a

I believe this should be a separate function(s) in some experimental Toml.Diff module. And design for this feature is a subject for discussion 🤔

@willbasky
Copy link
Collaborator

Ok. Then for this issue it will be within result message | Warning [DecodeWarning] a

And for other issue it will be separate function. And maybe we will find some other useful functions to be invented.

@willbasky
Copy link
Collaborator

Now we have DecodeException.
decode returns Either DecodeException a
Should it returns Result a? where

data Result a
    = DecodeException
    | Warning [DecodeWarning] a
    | Success a

@chshersh
Copy link
Contributor Author

chshersh commented Oct 9, 2019

@willbasky In future we might want to change decode to return Result. But only after this experimental approach will be battle-tested.

@willbasky
Copy link
Collaborator

So, now, should it be in separate module. Some decode-like function that returns Result a?

@chshersh
Copy link
Contributor Author

chshersh commented Oct 9, 2019

@willbasky Exactly

@chshersh
Copy link
Contributor Author

chshersh commented May 30, 2020

The function is starting to become more useful. So here is the roadmap for implementing the feature:

  • Implement the tomlDiff :: TOML -> TOML -> TOML function. This is probably the most difficult part of this issue.
  • Add one more constructor to TomlDecodeError, something like NotExactDecode TOML.
  • Implement the exactDecode function with the following logic:
    1. Run decode to get the value.
    2. Convert the resulting value back to TOML.
    3. Find diff between the original TOML and the resulting TOML.
    4. If the diff is not empty, fail with NotExactDecode TOML with diff inside error message
  • Write some tests 🙂

@vrom911 vrom911 added this to the v1.3.2.0: Always improving milestone Feb 9, 2021
@vrom911 vrom911 self-assigned this Feb 9, 2021
vrom911 added a commit that referenced this issue Feb 12, 2021
chshersh pushed a commit that referenced this issue Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
λ-safe Type safety, validation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants