arthurdent75 / SimpleScheduler

An Home Assistant AddOn to schedule entities on/off on weekly base
183 stars 36 forks source link

Corrupted JSON files crash the addon #123

Closed vcasinha closed 1 year ago

vcasinha commented 1 year ago

Great addon, very useful and really simple to use. I've been using this addon since a few months. Recently it stopped working and there's nothing I can do to fix it.

I've removed it and reinstalled, multiple times and always get the same error when starting:

Repeating log: [09:37:27] INFO: Starting service.d [Interface] [09:37:28] INFO: Running interface.sh Traceback (most recent call last): File "/simplescheduler/main.py", line 788, in [2023-03-01 09:37:28] STATUS: Starting main program init() File "/simplescheduler/main.py", line 779, in init schedulers_list = load_json_schedulers() File "/simplescheduler/main.py", line 403, in load_json_schedulers ss.append(json.load(read_file)) File "/usr/lib/python3.9/json/init.py", line 293, in load return loads(fp.read(), File "/usr/lib/python3.9/json/init.py", line 346, in loads return _default_decoder.decode(s) File "/usr/lib/python3.9/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) [09:37:29] WARNING: example 2 crashed, halting add-on ./finish: line 7: /run/s6/basedir/bin/halt: No such file or directory

Don't know what else I should do to fix this. Thanks!

arthurdent75 commented 1 year ago

Every scheduler is saved as a single JSON file. Probably one of them is corrupted. You could try to back up them all, delete them from the folder, and then try to add them again one at a time.

vcasinha commented 1 year ago

You are right. For some reason there were 3 empty JSON files in the folder. After removing them, everything went back to normal. My suggestion would be to log the problem and jump to the next file, not letting this kind of error prevent from starting the service.

Thanks a lot for the support and the awesome tool!

arthurdent75 commented 1 year ago

My suggestion would be to log the problem and jump to the next file, not letting this kind of error prevent from starting the service.

You are right. In my defense, I could never imagine that a JSON file, created by the application itself, could be corrupted.

If you look closely, the error didn't generate from my code but from the python library that loads a JSON from a file, which says that the JSON format is invalid.

I did put some TRY...CATCH in the code where something could go wrong, but not that routine. I will manage the error in future releases, but it is still odd that this could happen...

BTW, thank you for warning me about this!