Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

[BUG] Serialization emits invalid file with missing sections #374

Open
Danvil opened this issue May 17, 2023 · 3 comments
Open

[BUG] Serialization emits invalid file with missing sections #374

Danvil opened this issue May 17, 2023 · 3 comments

Comments

@Danvil
Copy link

Danvil commented May 17, 2023

I have a large application where I dump about 30 MB worth of smaller objects into a file. All objects are using serde auto-derive [derive(Serialize, Deserialize)].

I am using serde_yaml = "0.9" and the code which writes my file looks like this:

let mut file = std::fs::OpenOptions::new()
  .write(true)
  .create(true)
  .open(filename)
  .context(filename.to_owned())?;
let mut out = BufWriter::new(file);
serde_yaml::to_writer(&mut out, &my_stuff).context("serialization to YAML")?;
out.flush()?;

(Note: I tried and it also happens without the BufWriter.)

my_stuff above is a large map with about 20000 objects.

Unfortunately this emits an invalid YAML file where there are obviously some pieces missing. Here is an excerpt of the file which was written:

    SelectionMarker:
      color:
        r: 1.0
        g: 1.0
        b: 1.0
      is_visible: true
      is_selected: false
:
      food: 30.0
      food_current: 30.0
      water: 20.0

There is a single line with a stray : and there is some data missing at that location.

So far I can say: it does seem to happen exactly once in the file and it happens towards the end of the file (this was line 1727330 of 1743267).

@dtolnay
Copy link
Owner

dtolnay commented May 17, 2023

"Stray :" is not necessarily invalid YAML. You are just showing an excerpt of the output but the following is valid YAML syntax:

?
    SelectionMarker:
      color:
        r: 1.0
        g: 1.0
        b: 1.0
      is_visible: true
      is_selected: false
:
      food: 30.0
      food_current: 30.0
      water: 20.0

@dtolnay
Copy link
Owner

dtolnay commented May 17, 2023

Since what you showed is valid YAML, this issue is not going to be actionable unless you can provide a minimal repro of incorrect behavior.

@Danvil
Copy link
Author

Danvil commented May 20, 2023

There is no ? before in the file. There is simply content missing at the location where the : appears in the file. The emitted file does not pass the serialize - deserialize test and panics during deserialization with serde_yaml.

When I switch to JSON by simply replacing serde_yaml::to_writer with serde_json::to_writer_pretty it is working fine.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants