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

macOS: TOML with Table values produces error on output #194

Open
rqelibari opened this issue Dec 29, 2018 · 3 comments · May be fixed by #221
Open

macOS: TOML with Table values produces error on output #194

rqelibari opened this issue Dec 29, 2018 · 3 comments · May be fixed by #221

Comments

@rqelibari
Copy link

rqelibari commented Dec 29, 2018

The Problem

Trying to output the data structure in TOML format (with -T option) produces an error on macOS High Sierra:

$ rq -tT 'id' < ./test.toml
 [ERROR] [rq] Encountered: values must be emitted before tables
 [ERROR] [rq] (Re-run with --trace or RUST_BACKTRACE=1 for a backtrace)

Investigations

Doing a web search with that error message led me to this source file of the toml crate project, that is responsible for serialising the data structure to a TOML file, that states:

Note that the TOML format has a restriction that if a table itself contains
tables, all keys with non-table values must be emitted first. This is
typically easy to ensure happens when you're defining a `struct` as you can
reorder the fields manually, but when working with maps (such as `BTreeMap`
or `HashMap`) this can lead to serialization errors. In those situations you
may use the `tables_last` function in this module [...]

And indeed, the error occurred only when there were tables to be serialised.

Solution

As stated in the serialisation source file, a solution is to make use of the tables_last function. I am currently figuring out, how I need to adapt the rq/src/value/toml.rs source file to do exactly that.

Any help is appreciated, especially as I have started learning Rust only a few days ago.

@rqelibari
Copy link
Author

A workaround for now is to use the order preserving linked-hash-map instead of the BTreeMap.
Take a look at it on my fork.

@dflemstr
Copy link
Owner

dflemstr commented Feb 3, 2019

Sounds like a reasonable change, maybe you want to make a PR? I don't think any logic should depend on object key order within rq right now (maybe some tests need tweaking)

@Nemo157
Copy link

Nemo157 commented Jun 3, 2020

Order preservation is not enough when you are doing something like --input-json --output-toml, the json may not be in the correct order to start with.

@JoelColledge JoelColledge linked a pull request Nov 12, 2021 that will close this issue
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 a pull request may close this issue.

3 participants