jtc
jtc copied to clipboard
source JSON might be lost in a corner case
When option -f is used (to update the output right into the source JSON file) and either of these failures occur:
fail: template argument failed interpolationfail: file <name> holds an invalid JSONfail: argument walk-type (<walk>) not allowed, due to mode <mode> already setfail: non-walk argument <arg> not allowed, due to option -<opt> givenfail: non-walk argument <arg> not allowed, due to mode <mode> already set
then the source JSON file is lost (becomes empty)
Analysis:
When either of the reported failures happen (given option -f), they occur after source JSON file already open for write (and hence already truncated).
One of the feasible solutions: reinstate (rewrite) source JSON into the source file upon those cases. Reinstating of the source JSON is preferable solution (vs delaying opening file for write) for couple reasons:
- it's much easier/logical from the code design point of view
- some of the failures may occur when output JSON might be partially written and thus may result in an inconsistent output
Will be committing changes soon.