Skip to content

Commit

Permalink
Tweak exception output to use !r
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Booth committed Aug 6, 2018
1 parent 1956b9d commit 55da063
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions electrumx/server/peers.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ async def _should_drop_peer(self, peer):
is_good = True
break
except BadPeerError as e:
self.logger.error(f'{peer_text} marking bad: ({e})')
self.logger.error(f'{peer_text} marking bad: ({e!r})')
peer.mark_bad()
break
except RPCError as e:
Expand All @@ -240,7 +240,7 @@ async def _should_drop_peer(self, peer):
except TaskTimeout as e:
self.logger.error(f'{peer_text} timed out after {e.args[0]}s')
except (OSError, SOCKSError, ConnectionError) as e:
self.logger.info(f'{peer_text} {e}')
self.logger.info(f'{peer_text} {e!r}')

if is_good:
now = time.time()
Expand Down
21 changes: 11 additions & 10 deletions electrumx/server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,10 @@ async def _start_server(self, kind, *args, **kw_args):
try:
self.servers[kind] = await server
except Exception as e:
self.logger.error('{} server failed to listen on {}:{:d} :{}'
.format(kind, host, port, e))
self.logger.error(f'{kind} server failed to listen on {host}:'
f'{port:d} :{e!r}')
else:
self.logger.info('{} server listening on {}:{:d}'
.format(kind, host, port))
self.logger.info(f'{kind} server listening on {host}:{port:d}')

async def _start_external_servers(self):
'''Start listening on TCP and SSL ports, but only if the respective
Expand Down Expand Up @@ -363,7 +362,7 @@ async def rpc_daemon_url(self, daemon_url):
try:
daemon_url = self.chain_state.set_daemon_url(daemon_url)
except Exception as e:
raise RPCError(BAD_REQUEST, f'an error occured: {e}')
raise RPCError(BAD_REQUEST, f'an error occured: {e!r}')
return f'now using daemon at {daemon_url}'

async def rpc_stop(self):
Expand Down Expand Up @@ -588,7 +587,9 @@ def sub_count(self):
return 0

async def handle_request(self, request):
'''Return the async handler for the given request method.'''
'''Handle an incoming request. ElectrumX doesn't receive
notifications from client sessions.
'''
if isinstance(request, Request):
handler = self.request_handlers.get(request.method)
else:
Expand Down Expand Up @@ -658,7 +659,7 @@ async def daemon_request(self, method, *args):
try:
return await self.chain_state.daemon_request(method, args)
except DaemonError as e:
raise RPCError(DAEMON_ERROR, f'daemon error: {e}')
raise RPCError(DAEMON_ERROR, f'daemon error: {e!r}') from None

def sub_count(self):
return len(self.hashX_subs)
Expand Down Expand Up @@ -1016,7 +1017,7 @@ async def banner(self):
with codecs.open(banner_file, 'r', 'utf-8') as f:
banner = f.read()
except Exception as e:
self.logger.error(f'reading banner file {banner_file}: {e}')
self.logger.error(f'reading banner file {banner_file}: {e!r}')
else:
banner = await self.replaced_banner(banner)

Expand Down Expand Up @@ -1091,7 +1092,7 @@ async def transaction_broadcast(self, raw_tx):
except DaemonError as e:
error, = e.args
message = error['message']
self.logger.info('sendrawtransaction: {}'.format(message))
self.logger.info(f'sendrawtransaction: {message}')
raise RPCError(BAD_REQUEST, 'the transaction was rejected by '
f'network rules.\n\n{message}\n[{raw_tx}]')

Expand Down Expand Up @@ -1277,7 +1278,7 @@ async def masternode_announce_broadcast(self, signmnb):
except DaemonError as e:
error, = e.args
message = error['message']
self.logger.info('masternode_broadcast: {}'.format(message))
self.logger.info(f'masternode_broadcast: {message}')
raise RPCError(BAD_REQUEST, 'the masternode broadcast was '
f'rejected.\n\n{message}\n[{signmnb}]')

Expand Down

0 comments on commit 55da063

Please sign in to comment.