Closed NLZ closed 3 years ago
If the json is incorrect (for example script failed on Issue #5) then it leaves behind an invalid json. My suggestion would be to catch errors from the json loading https://github.com/Rudoal/mdownloader/blob/9114ed091215d9da60ee2f2526c78d6c9a214065/components/jsonmaker.py#L182-L188 So here I would do it like this:
def checkExist(self): if os.path.exists(self.json_path): try: with open(self.json_path, 'r') as file: series_json = json.load(file) return series_json except json.decoder.JSONDecodeError: return {} else: return {}
Here is the error trace:
Traceback (most recent call last): File "C:\Users\nlz\Code\mdownloader\mdownloader.py", line 120, in <module> before_main(args.id, args.language, args.directory, args.type, args.folder, args.save_format, args.covers) File "C:\Users\nlz\Code\mdownloader\mdownloader.py", line 102, in before_main main(id, language, directory, type, folder, save_format, covers) File "C:\Users\nlz\Code\mdownloader\components\main.py", line 103, in main typeChecker(id, language, route, type, make_folder, save_format, covers) File "C:\Users\nlz\Code\mdownloader\components\main.py", line 18, in typeChecker downloadBatch(id, language, route, type, make_folder, save_format, covers) File "C:\Users\nlz\Code\mdownloader\components\downloader.py", line 184, in downloadBatch json_file = TitleJson(data, series_route, covers) File "C:\Users\nlz\Code\mdownloader\components\jsonmaker.py", line 22, in __init__ self.data_json = self.checkExist() File "C:\Users\nlz\Code\mdownloader\components\jsonmaker.py", line 186, in checkExist series_json = json.load(file) File "C:\Python39\lib\json\__init__.py", line 293, in load return loads(fp.read(), File "C:\Python39\lib\json\__init__.py", line 346, in loads return _default_decoder.decode(s) File "C:\Python39\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python39\lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 24 column 26 (char 805)
(maybe I should've done a pull request, but I'm too lazy tonight)
Fixed in 2.7.2, I just saw these issues before going to bed, good thing they weren't too hard to fix.
If the json is incorrect (for example script failed on Issue #5) then it leaves behind an invalid json. My suggestion would be to catch errors from the json loading https://github.com/Rudoal/mdownloader/blob/9114ed091215d9da60ee2f2526c78d6c9a214065/components/jsonmaker.py#L182-L188 So here I would do it like this:
Here is the error trace:
(maybe I should've done a pull request, but I'm too lazy tonight)