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

sync: fix null handling when updating filepaths/metadata #501

Merged
merged 3 commits into from
Jan 27, 2022

Conversation

ee7
Copy link
Member

@ee7 ee7 commented Jan 25, 2022

For now, let's resolve the problem by stripping any optional key with
the value of null when updating filepaths or metadata.

Edit: Okay, I've tried to keep preserving the null during sync (fmt strips it).


Before this commit, when updating a .meta/config.json file that
contained an optional key with the value of null, configlet would
produce an UnpackDefect. For example, the below tries to update a
file that contains "contributors": null:

$ git clone https://github.com/exercism/common-lisp
$ cd common-lisp
$ git checkout 4fc524e24a69
$ configlet sync --metadata -e binary -u
Checking exercises...
Cloning https://github.com/exercism/problem-specifications/... success
[warn] metadata: unsynced: binary
sync the above metadata ([y]es/[n]o)? y
options.nim(194)         get
Error: unhandled exception: Can't obtain a value from a `none` [UnpackDefect]

configlet fmt removes optional key/value pairs when the value is
null, and only the Common Lisp and Julia tracks had such a value, but
configlet sync -u should still handle this situation properly.

The bug: our pretty proc serializes from a list of keys, and relied on
optional values being non-null. configlet fmt added only keys with
non-null values to that list, but configlet sync tried to preserve
null values to reduce noise in diffs.

Fix by ensuring that pretty in sync mode can no longer sometimes use
get with a none.

Fixes: #500

Before this commit, when updating a `.meta/config.json` file that
contained an optional key with the value of `null`, configlet would
produce an `UnpackDefect`. For example:

    git clone https://github.com/exercism/common-lisp
    cd common-lisp
    git checkout 4fc524e24a69
    configlet sync --metadata -e binary -u
    Checking exercises...
    Cloning https://github.com/exercism/problem-specifications/... success
    [warn] metadata: unsynced: binary
    sync the above metadata ([y]es/[n]o)? y
    options.nim(194)         get
    Error: unhandled exception: Can't obtain a value from a `none` [UnpackDefect]

For now, let's resolve the problem by stripping any optional key with
the value of `null` when updating filepaths or metadata.

Fixes: 500
@ee7
Copy link
Member Author

ee7 commented Jan 25, 2022

I wasn't satisfied with removing the null during sync -u, so I've added a proc that can append a key/null pair instead.

It turns out that this bug would also have affected updating filepaths on the Julia track:

$ find . -path '*.meta/config.json' -exec grep ':\s*null' {} +
./julia/exercises/concept/emoji-times/.meta/config.json:  "forked_from": null
./julia/exercises/concept/encounters/.meta/config.json:  "forked_from": null
./julia/exercises/concept/exercism-matrix/.meta/config.json:  "forked_from": null
./julia/exercises/concept/fibonacci-iterator/.meta/config.json:  "forked_from": null
./julia/exercises/concept/stage-heralding/.meta/config.json:  "forked_from": null

@ee7 ee7 merged commit 4ccb2e3 into exercism:main Jan 27, 2022
@ee7 ee7 deleted the sync-fix-null-handling-when-updating branch January 27, 2022 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sync throws error when config.json has "contributors": null
2 participants