Skip to content

Commit 7d8d22b

Browse files
committed
Add an exception when loading a non-existent file.
1 parent 37d13fc commit 7d8d22b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

json_duplicate_keys/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,15 @@ def __convert_Jloads_to_Jobj(Jloads, Jobj):
178178
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
179179
def load(Jfilepath, dupSign_start="{{{", dupSign_end="}}}", ordered_dict=False, skipDuplicated=False, _isDebug_=False):
180180
try:
181-
with open(Jfilepath) as Jfile: Jstr = Jfile.read()
182-
except Exception as e:
183-
with open(Jfilepath, "rb") as Jfile: Jstr = Jfile.read()
181+
try:
182+
with open(Jfilepath) as Jfile: Jstr = Jfile.read()
183+
except Exception as e:
184+
with open(Jfilepath, "rb") as Jfile: Jstr = Jfile.read()
184185

185-
return loads(Jstr, dupSign_start=dupSign_start, dupSign_end=dupSign_end, ordered_dict=ordered_dict, skipDuplicated=skipDuplicated, _isDebug_=_isDebug_)
186+
return loads(Jstr, dupSign_start=dupSign_start, dupSign_end=dupSign_end, ordered_dict=ordered_dict, skipDuplicated=skipDuplicated, _isDebug_=_isDebug_)
187+
except Exception as e:
188+
if _isDebug_: print("\x1b[31m[-] ExceptionError: {}\x1b[0m".format(e))
189+
return False
186190
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
187191
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
188192
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

0 commit comments

Comments
 (0)