ijpiantanida / talkback

A simple HTTP proxy that records and playbacks requests
MIT License
283 stars 41 forks source link

Numbering can cause errors if previous tape was deleted #91

Closed raphaeleidus closed 3 months ago

raphaeleidus commented 4 months ago

so by default the tapes get named unnamed-<number>.json5 if you have a few tapes and you haven't manually renamed them and you delete one from the middle. example:

unnamed-1.json5
unnamed-2.json5
(deleted tape because it became unused)
unnamed-4.json5

the default numbering will calculate that there are currently 3 tapes and the next tape should be saved at unnamed-4.json5 which will overwrite the previous tape.

Suggestion, switch to a different naming convention that is resilient to this... I will submit a PR shortly, it will likely mean a breaking change to the signature of the tapeNameGenerator function.

raphaeleidus commented 4 months ago

alternative suggestion... before writing the file, try to parse what numbers are in use... but this is also really challenging, as if a use has provided a tapeNameGenerator function that changes how they are named from unnamed-<tapeNumber>.json5 to something like <tapeNumber>-unnamed.json5 the parsing wont see it.

Theoretically, we could have talkback call the tapeNameGenerator then check if there is already a file in that location and if there is, increment the tapeCount by 1 and call it again... and repeat... this is probably the safest approach that wont cause a change in the API

ijpiantanida commented 3 months ago

Addressed in 4.1.0 (CHANGELOG)