Skip to content

Commit ec05666

Browse files
committed
readFile fixes
1 parent 17948c8 commit ec05666

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/misc.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,12 @@ def readCacheFile():
224224
cache = json.load(data_file)
225225

226226
else:
227-
writeToFile(DEFAULT_CACHE, cache_File)
228-
raise Exception("No cache file found. Creating new.")
227+
resetCacheFile()
229228

230229
except Exception as e:
231-
printDbg(e.args[0])
230+
if e.args is not None:
231+
printDbg(e.args[0])
232+
resetCacheFile()
232233
return DEFAULT_CACHE
233234

234235
# Fix missing data in cache
@@ -254,11 +255,12 @@ def readMNfile():
254255

255256
else:
256257
# save default config (empty list) and return it
257-
writeToFile([], masternodes_File)
258-
raise Exception("No masternodes file found. Creating new.")
258+
resetMNfile()
259259

260260
except Exception as e:
261-
printDbg(e.args[0])
261+
if e.args is not None:
262+
printDbg(e.args[0])
263+
resetMNfile()
262264
return []
263265

264266
# Fix missing data
@@ -287,19 +289,20 @@ def readRPCfile():
287289
urlstring = "http://%s:%s@%s:%d" % (
288290
rpc_config.get('rpc_user'), rpc_config.get('rpc_password'),
289291
rpc_config.get('rpc_ip'), int(rpc_config.get('rpc_port')))
290-
if not checkRPCstring(urlstring):
292+
if not checkRPCstring(urlstring, action_msg="unable to read RPC configuration"):
291293
# save default config and return it
292-
resetRPCfile()
293-
rpc_config = DEFAULT_RPC_CONF
294+
raise
294295

295296
else:
296297
printDbg("No rpcServer.json found.")
297298
# save default config and return it
298-
resetRPCfile()
299-
rpc_config = DEFAULT_RPC_CONF
299+
raise
300300

301301
except Exception as e:
302-
printDbg(e.args[0])
302+
if e.args is not None:
303+
printDbg(e.args[0])
304+
resetRPCfile()
305+
rpc_config = DEFAULT_RPC_CONF
303306

304307
rpc_ip = rpc_config.get('rpc_ip')
305308
rpc_port = int(rpc_config.get('rpc_port'))
@@ -313,6 +316,14 @@ def resetRPCfile():
313316
printDbg("Creating default rpcServer.json")
314317
writeToFile(DEFAULT_RPC_CONF, rpc_File)
315318

319+
def resetMNfile():
320+
printDbg("Creating empty masternodes.json")
321+
writeToFile([], masternodes_File)
322+
323+
def resetCacheFile():
324+
printDbg("No cache file found. Creating new.")
325+
writeToFile(DEFAULT_CACHE, cache_File)
326+
316327

317328

318329
def checkRPCstring(urlstring, action_msg="Resetting default credentials"):

0 commit comments

Comments
 (0)