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

Use --stringify in remarshal #55

Merged
merged 2 commits into from
Nov 11, 2024
Merged

Conversation

Mr-Andersen
Copy link
Contributor

I've got this error: Error: Cannot convert data to JSON (Object of type datetime is not JSON serializable), coming from remarshal. Fixed it in this commit. Fix was tested in local environment

@cdepillabout
Copy link
Owner

@Mr-Andersen Do you have an example of your stack.yaml / stack.yaml.lock that is triggering this problem?

I didn't realize this, but it appears there is some notion of dates within yaml files? https://yaml.org/spec/1.2.2/#tags And by default remarshal tries to parse these and output actual dates in the resulting JSON, but fails because JSON doesn't have a concept of a date?

The --stringify option on remarshal has the following documentation (https://github.com/remarshal-project/remarshal):

  -k, --stringify       turn into strings: boolean and null keys and date-time
                        keys and values for JSON; boolean, date-time, and null
                        keys and null values for TOML

From this definition it sounds like in addition to turning date-time keys and values in strings, it also turns boolean and null keys into strings? I guess this is alright and wouldn't cause a problem anywhere?

@Mr-Andersen
Copy link
Contributor Author

Do you have an example of your stack.yaml / stack.yaml.lock that is triggering this problem?

Here is the file: https://github.com/commercialhaskell/stackage-snapshots/blob/master/nightly/2024/11/9.yaml. I guess this is the problematic line.

I guess this is alright and wouldn't cause a problem anywhere?

YAML doesn't have non-string keys, as far as I know, so it should be OK.

@Mr-Andersen
Copy link
Contributor Author

Oh, to be clear: my stack.yaml was just resolver: nightly-2024-11-09. That's the important part :) You can reproduce it locally, I'm sure.

@Mr-Andersen
Copy link
Contributor Author

Oh, I tried switching back to LTS (lts-22.41) and your branch and it happens with LTS too. I'm guessing stackage adds this date now everywhere?

@cdepillabout
Copy link
Owner

@Mr-Andersen Thanks a lot for fixing this and giving an example where it fails!

I submitted a bug upstream to remarshal, since it seems quite surprising that this --stringify option isn't the default: remarshal-project/remarshal#53

@cdepillabout
Copy link
Owner

Hmm, so it looks like remarshal only got this new --stringify argument starting in 0.17.0, so we'll have to put in a conditional to only include the --stringify argument in newer versions. This is quite annoying. I should really just rip out remarshal and go with a better tool.

@cdepillabout
Copy link
Owner

@Mr-Andersen I pushed a commit only conditionally using --stringify if remarshal is new enough. Can you confirm this works for your setup?

@Mr-Andersen
Copy link
Contributor Author

Yep, it works :)

@cdepillabout cdepillabout merged commit feb280d into cdepillabout:main Nov 11, 2024
2 checks passed
@cdepillabout
Copy link
Owner

Thanks! I've released this as https://github.com/cdepillabout/stacklock2nix/releases/tag/v4.1.0

@Mr-Andersen
Copy link
Contributor Author

Thank you for making such simple and well-documented tool! A breath of fresh air after haskell.nix :)

@Mr-Andersen Mr-Andersen deleted the patch-1 branch November 12, 2024 13:10
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.

2 participants