Easiest way to reproduce is to try to use a non-existing config file path:
muon fmt -i -c /file/that/does/not/exist meson.build
.
However, this also happens if there is an error in the configuration file, or there was an error while parsing meson.build, etc.
This happens because target file path is opened for writing before calling fmt().
I think the best way to fix this would be to instead write to a file called $target_file.$pid.tmp
or something along the lines, and then rename it $target_value
essentially overwriting the fie.
This should be fixed now. Since we already have the original file contents in memory, I implemented this by just rewriting those original contents to the file if an error occurs.
I also found out that
fmt -i -q meson.build
will truncate the file, and fixed that by erroring if both-i
and-q
are passed.