Add error logging

This commit is contained in:
Arinerron 2018-04-18 18:57:37 -07:00
parent 86a2c0d6d0
commit ded179bcad
No known key found for this signature in database
GPG Key ID: 99383627861C62F0
2 changed files with 17 additions and 12 deletions

View File

@ -216,9 +216,11 @@ def warn(data, timestamp=True):
log('!', data, colors.fg.orange, timestamp=timestamp)
# error: when only one function, module, or process of the program encountered a problem and must stop
def error(data, timestamp=True):
def error(data, error=None, timestamp=True):
if get_level() <= LEVEL_ERROR:
log('-', data, colors.fg.red, timestamp=timestamp)
if not error is None:
debug('Error details: ' + str(error))
# fatal: when the something so bad has happened that the prorgam must stop
def fatal(data, timestamp=True):

View File

@ -291,15 +291,18 @@ class OnionrUtils:
for i in blocks:
if len (i) == 0:
continue
with open('data/blocks/' + i + '.dat', 'r') as potentialMessage:
message = potentialMessage.read()
if message.startswith('-pm-'):
try:
message = self._core._crypto.pubKeyDecrypt(message.replace('-pm-', ''), encodedData=True, anonymous=True)
except nacl.exceptions.CryptoError as e:
#logger.debug('Unable to decrypt ' + i)
#logger.debug(str(e))
pass
else:
logger.info('Recieved message: ' + message.decode())
try:
with open('data/blocks/' + i + '.dat', 'r') as potentialMessage:
message = potentialMessage.read()
if message.startswith('-pm-'):
try:
message = self._core._crypto.pubKeyDecrypt(message.replace('-pm-', ''), encodedData=True, anonymous=True)
except nacl.exceptions.CryptoError as e:
#logger.debug('Unable to decrypt ' + i)
#logger.debug(str(e))
pass
else:
logger.info('Recieved message: ' + message.decode())
except Exception as error:
logger.error('Failed to open block ' + str(i) + '.', error=error)
return