Tech
Make Your CLI Config Write Survive Ctrl-C Without Leaving Truncated JSON
A small CLI reads config.json , changes one field, and writes the file back. The code looks harmless:
await writeFile ( path , JSON . stringify ( next , null , 2 ));
Then the process is interrupted during the write. The next run finds 347 bytes of what used to be a 2 KB file, JSON parsing fails, and a one-line settings command has become a recovery exercise.
The useful contract is not “the write usually succeeds.” It is:
After an interruption, the c...
Read the full discussion on Dev.to
This article was aggregated from Dev.to. Click to join the conversation.
View on Dev.to