Skip to content

Commit

Permalink
added more exception logging
Browse files Browse the repository at this point in the history
  • Loading branch information
gretzke committed Dec 10, 2019
1 parent aec62fa commit c99bb1f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
19 changes: 16 additions & 3 deletions plug_py/plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ def run(self):
except timeout:
window.updateInfo('No smart socket found')
window.updateInfoCenter('')
except:
except Exception as e:
print(e)
window.resetToStart()
window.updateInfo('An error occurred')

Expand Down Expand Up @@ -373,17 +374,22 @@ async def receiveMessage(self):
except asyncio.TimeoutError:
# no new message
pass
except Exception as e:
print(e)
raise e

# received message
if message != None:
try:
# parse JSON of message
parsedMessage = json.loads(message)
print(parsedMessage)

except JSONDecodeError:
print('Received message could not be parsed: ' + message)
pass
except Exception as e:
print(e)
raise e

# execute code according to states
if parsedMessage['id'] == State.connected_S.value:
Expand Down Expand Up @@ -451,6 +457,9 @@ async def connected_S(self, parsedMessage):
transactionHash)
except TransactionNotFound:
pass
except Exception as e:
print(e)
raise e
QThread.sleep(1)

if (transactionReceipt.status != 1):
Expand Down Expand Up @@ -537,6 +546,9 @@ async def initialized_P(self):
transactionHash)
except TransactionNotFound:
pass
except Exception as e:
print(e)
raise e
await asyncio.sleep(1)

if (transactionReceipt.status == 1):
Expand Down Expand Up @@ -634,7 +646,8 @@ async def wsConnection(self):
try:
# wait until connected to websocket
self.websocket = await websockets.connect(self.IP)
except:
except Exception as e:
print(e)
# if connection times out close thread
window.ui.startButton.setVisible(True)
window.updateInfoCenter('')
Expand Down
27 changes: 12 additions & 15 deletions socket_py/socket_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,6 @@ def closeEvent(self, event):
# GPIO.cleanup()
event.accept() # let the window close

def terminateThread(self, process):
try:
thread = operator.attrgetter(process)(self)
if thread.threadActive:
thread.threadActive = False
thread.quit()
if (thread.wait(1000) == False):
thread.terminate()
thread.wait()
except AttributeError:
# thread was not created yet
pass

def updateInfoCenter(self, str):
if (str == ''):
self.ui.infoCenterLabel.setVisible(False)
Expand Down Expand Up @@ -292,7 +279,9 @@ async def wsServer(self, websocket, path):

elif self.paymentState == State.closed:
await self.closed()

except Exception as e:
print(e)
raise e
finally:
self.websocket = None
self.connected.remove(websocket)
Expand All @@ -309,17 +298,22 @@ async def receiveMessage(self):
except asyncio.TimeoutError:
# no new message
pass
except Exception as e:
print(e)
raise e

# received message
if message != None:
try:
# parse JSON of message
parsedMessage = json.loads(message)
print(parsedMessage)

except JSONDecodeError:
print('Received message could not be parsed: ' + message)
pass
except Exception as e:
print(e)
raise e

# execute code according to states
if parsedMessage['id'] == State.connected_P.value:
Expand Down Expand Up @@ -436,6 +430,9 @@ async def closed(self):
transactionHash)
except TransactionNotFound:
pass
except Exception as e:
print(e)
raise e
QThread.sleep(1)

window.updateInfoCenter('Successfully closed\nPayment Channel')
Expand Down

0 comments on commit c99bb1f

Please sign in to comment.