Skip to content

Minor Exception cleanup #1317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kafka/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
SSLWantReadError = ssl.SSLWantReadError
SSLWantWriteError = ssl.SSLWantWriteError
SSLZeroReturnError = ssl.SSLZeroReturnError
except:
except AttributeError:
# support older ssl libraries
log.warning('Old SSL module detected.'
' SSL error handling may not operate cleanly.'
Expand Down
4 changes: 2 additions & 2 deletions kafka/consumer/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ def _unpack_message_set(self, tp, records):
# caught by the generator. We want all exceptions to be raised
# back to the user. See Issue 545
except StopIteration as e:
log.exception('StopIteration raised unpacking messageset: %s', e)
raise Exception('StopIteration raised unpacking messageset')
log.exception('StopIteration raised unpacking messageset')
raise RuntimeError('StopIteration raised unpacking messageset')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially this should be a KafkaError although I'm unclear when to reach for that instead of RuntimeError

Copy link
Collaborator

@tvoinarovskyi tvoinarovskyi Dec 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuntimeError is what would be raised by the convention on Python3 if we have a not handled StopIteration raised inside of a generator, so seems fine to me


def __iter__(self): # pylint: disable=non-iterator-returned
return self
Expand Down
4 changes: 2 additions & 2 deletions kafka/metrics/metric_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def __init__(self, name, group, description=None, tags=None):
tags (dict, optional): Additional key/val attributes of the metric.
"""
if not (name and group):
raise Exception('name and group must be non-empty.')
raise ValueError('name and group must be non-empty.')
if tags is not None and not isinstance(tags, dict):
raise Exception('tags must be a dict if present.')
raise ValueError('tags must be a dict if present.')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, both of these could be changed to KafkaConfigurationError


self._name = name
self._group = group
Expand Down
2 changes: 1 addition & 1 deletion kafka/protocol/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def repr(self, value):
field_val = value[i]
key_vals.append('%s=%s' % (self.names[i], self.fields[i].repr(field_val)))
return '(' + ', '.join(key_vals) + ')'
except:
except Exception:
return repr(value)


Expand Down
4 changes: 2 additions & 2 deletions test/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def open(self):
time.sleep(backoff)
tries += 1
else:
raise Exception('Failed to start Zookeeper before max_timeout')
raise RuntimeError('Failed to start Zookeeper before max_timeout')
self.out("Done!")
atexit.register(self.close)

Expand Down Expand Up @@ -302,7 +302,7 @@ def open(self):
time.sleep(backoff)
tries += 1
else:
raise Exception('Failed to start KafkaInstance before max_timeout')
raise RuntimeError('Failed to start KafkaInstance before max_timeout')
self.out("Done!")
self.running = True
atexit.register(self.close)
Expand Down
2 changes: 1 addition & 1 deletion test/test_failover_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def _send_random_messages(self, producer, topic, partition, n):
while True:
try:
producer.send_messages(topic, partition, msg.encode('utf-8'))
except:
except Exception:
log.exception('failure in _send_random_messages - retrying')
continue
else:
Expand Down
2 changes: 1 addition & 1 deletion test/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def tearDown(self):
def current_offset(self, topic, partition):
try:
offsets, = self.client.send_offset_request([OffsetRequestPayload(topic, partition, -1, 1)])
except:
except Exception:
# XXX: We've seen some UnknownErrors here and can't debug w/o server logs
self.zk.child.dump_logs()
self.server.child.dump_logs()
Expand Down