Skip to content
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

Fix exception causes all over the codebase #554

Merged
merged 1 commit into from
Jun 15, 2020
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
4 changes: 2 additions & 2 deletions jupyter_client/asynchronous/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ async def _recv_reply(self, msg_id, timeout=None, channel='shell'):
reply = await self.get_control_msg(timeout=timeout)
else:
reply = await self.get_shell_msg(timeout=timeout)
except Empty:
raise TimeoutError("Timeout waiting for reply")
except Empty as e:
raise TimeoutError("Timeout waiting for reply") from e
if reply['parent_header'].get('msg_id') != msg_id:
# not my reply, someone may have forgotten to retrieve theirs
continue
Expand Down
4 changes: 2 additions & 2 deletions jupyter_client/blocking/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def _recv_reply(self, msg_id, timeout=None, channel='shell'):
reply = self.get_control_msg(timeout=timeout)
else:
reply = self.get_shell_msg(timeout=timeout)
except Empty:
raise TimeoutError("Timeout waiting for reply")
except Empty as e:
raise TimeoutError("Timeout waiting for reply") from e
if reply['parent_header'].get('msg_id') != msg_id:
# not my reply, someone may have forgotten to retrieve theirs
continue
Expand Down
13 changes: 7 additions & 6 deletions jupyter_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,9 @@ def _signature_scheme_changed(self, change):
hash_name = new.split('-', 1)[1]
try:
self.digest_mod = getattr(hashlib, hash_name)
except AttributeError:
raise TraitError("hashlib has no such attribute: %s" % hash_name)
except AttributeError as e:
raise TraitError("hashlib has no such attribute: %s" %
hash_name) from e
self._new_auth()

digest_mod = Any()
Expand Down Expand Up @@ -537,7 +538,7 @@ def _check_packers(self):
jsonmsg = ""
raise ValueError(
msg.format(packer=self.packer, e=e, jsonmsg=jsonmsg)
)
) from e

# ensure packed message is bytes
if not isinstance(packed, bytes):
Expand All @@ -555,7 +556,7 @@ def _check_packers(self):
jsonmsg = ""
raise ValueError(
msg.format(packer=self.packer, unpacker=self.unpacker, e=e, jsonmsg=jsonmsg)
)
) from e

# check datetime support
msg = dict(t=utcnow())
Expand Down Expand Up @@ -733,8 +734,8 @@ def send(self, stream, msg_or_type, content=None, parent=None, ident=None,
try:
# check to see if buf supports the buffer protocol.
view = memoryview(buf)
except TypeError:
raise TypeError("Buffer objects must support the buffer protocol.")
except TypeError as e:
raise TypeError("Buffer objects must support the buffer protocol.") from e
# memoryview.contiguous is new in 3.3,
# just skip the check on Python 2
if hasattr(view, 'contiguous') and not view.contiguous:
Expand Down
4 changes: 2 additions & 2 deletions jupyter_client/ssh/tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ def openssh_tunnel(lport, rport, server, remoteip='127.0.0.1', keyfile=None, pas
raise SSHException('The authenticity of the host can\'t be established.')
except pexpect.TIMEOUT:
continue
except pexpect.EOF:
except pexpect.EOF as e:
if tunnel.exitstatus:
print(tunnel.exitstatus)
print(tunnel.before)
print(tunnel.after)
raise RuntimeError("tunnel '%s' failed to start" % (cmd))
raise RuntimeError("tunnel '%s' failed to start" % (cmd)) from e
else:
return tunnel.pid
else:
Expand Down