Do not crash with malformed visitors.json files#35
Do not crash with malformed visitors.json files#35marado wants to merge 3 commits intojifunks:masterfrom
Conversation
If the visitors.json file does not contain a valid JSON file, reset it, and act as if it was empty.
|
Doesn't this imply someone could just kill someone else's plant by making the JSON file invalid if their owner did not visit in 5 days, since the game will act as if nobody visited at all? the visit option is made to allow others to babysit your plant if you're away for more than 5 days so that would be a problem. What about 'just' crashing but with a readable error message, or just preventing the death detection from triggering in this case and giving the owner a last chance? |
|
Well, I think it is all a question of... design, more than implementation.
I prefer the first one, just because (a) relying on others to water your plants is always a risk, and (b) if we "assume the best" this is also a cheating mechanism (just mess up with the visitor.json file to make sure your plan never dies). I don't have strong feelings about this matter, I just did what seemed to make most sense to me. If we want a different behavior than the one currently implemented (eg, preventing death detection on this case), I can make the needed changes, but I suppose a decision should be made before I throw more code into the PR. |
|
I think the best would be not to take any automatic action but leave it up to the user. Maybe it would be best to make a prompt if visitors.json is malformed: the user can choose to either have it deleted automatically, or to try to fix it manually (which will close botany while printing instructions on how the file should look) |
If the visitors.json file does not contain a valid JSON file, reset
it, and act as if it was empty.
This crash was mentioned initially in #34 .