Use Exception.message in copyutil.py only if it exists

Exception.message was removed in Python 3, so only refer to it when it
exists on an Exception instance.

Also fix code style compliance in formatting.py (missing blank lines)

patch by Eduard Tudenhoefner; reviewed by Stefania Alborghetti for CASSANDRA-15702
This commit is contained in:
Eduard Tudenhoefner 2020-04-07 17:16:40 +02:00 committed by Stefania Alborghetti
parent 39a0703b65
commit 58015fd681
2 changed files with 6 additions and 4 deletions

View File

@ -146,7 +146,7 @@ class SendingChannel(object):
msg = self.pending_messages.get()
self.pipe.send(msg)
except Exception as e:
printmsg('%s: %s' % (e.__class__.__name__, e.message))
printmsg('%s: %s' % (e.__class__.__name__, e.message if hasattr(e, 'message') else str(e)))
feeding_thread = threading.Thread(target=feed)
feeding_thread.setDaemon(True)
@ -1342,7 +1342,7 @@ class FeedingProcess(mp.Process):
try:
reader.start()
except IOError as exc:
self.outmsg.send(ImportTaskError(exc.__class__.__name__, exc.message))
self.outmsg.send(ImportTaskError(exc.__class__.__name__, exc.message if hasattr(exc, 'message') else str(exc)))
channels = self.worker_channels
max_pending_chunks = self.max_pending_chunks
@ -1371,7 +1371,7 @@ class FeedingProcess(mp.Process):
if rows:
sent += self.send_chunk(ch, rows)
except Exception as exc:
self.outmsg.send(ImportTaskError(exc.__class__.__name__, exc.message))
self.outmsg.send(ImportTaskError(exc.__class__.__name__, exc.message if hasattr(exc, 'message') else str(exc)))
if reader.exhausted:
break
@ -2632,7 +2632,7 @@ class ImportProcess(ChildProcess):
pk = get_row_partition_key_values(row)
rows_by_ring_pos[get_ring_pos(ring, pk_to_token_value(pk))].append(row)
except Exception as e:
errors[e.message].append(row)
errors[e.message if hasattr(e, 'message') else str(e)].append(row)
if errors:
for msg, rows in errors.items():

View File

@ -239,6 +239,7 @@ def formatter_for(typname):
return f
return registrator
class BlobType(object):
def __init__(self, val):
self.val = val
@ -246,6 +247,7 @@ class BlobType(object):
def __str__(self):
return str(self.val)
@formatter_for('BlobType')
def format_value_blob(val, colormap, **_):
bval = ensure_text('0x') + ensure_text(binascii.hexlify(val))