jtc icon indicating copy to clipboard operation
jtc copied to clipboard

source JSON might be lost in a corner case

Open ldn-softdev opened this issue 4 years ago • 1 comments

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 interpolation
  • fail: file <name> holds an invalid JSON
  • fail: argument walk-type (<walk>) not allowed, due to mode <mode> already set
  • fail: non-walk argument <arg> not allowed, due to option -<opt> given
  • fail: non-walk argument <arg> not allowed, due to mode <mode> already set

then the source JSON file is lost (becomes empty)

ldn-softdev avatar Apr 15 '21 08:04 ldn-softdev

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:

  1. it's much easier/logical from the code design point of view
  2. 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.

ldn-softdev avatar Apr 15 '21 08:04 ldn-softdev