Skip to content

Fix exception causes all over the codebase #1168

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
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
6 changes: 3 additions & 3 deletions prompt_toolkit/input/vt100.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def __init__(self, stdin: TextIO) -> None:
try:
# This should not raise, but can return 0.
stdin.fileno()
except io.UnsupportedOperation:
except io.UnsupportedOperation as e:
if "idlelib.run" in sys.modules:
raise io.UnsupportedOperation(
"Stdin is not a terminal. Running from Idle is not supported."
)
) from e
else:
raise io.UnsupportedOperation("Stdin is not a terminal.")
raise io.UnsupportedOperation("Stdin is not a terminal.") from e

# Even when we have a file descriptor, it doesn't mean it's a TTY.
# Normally, this requires a real TTY device, but people instantiate
Expand Down
4 changes: 2 additions & 2 deletions prompt_toolkit/key_binding/bindings/named_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def get_by_name(name: str) -> Binding:
"""
try:
return _readline_commands[name]
except KeyError:
raise KeyError("Unknown Readline command: %r" % name)
except KeyError as e:
raise KeyError("Unknown Readline command: %r" % name) from e


#
Expand Down
4 changes: 2 additions & 2 deletions prompt_toolkit/layout/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def __init__(
if focused_element is None:
try:
self._stack.append(next(self.find_all_windows()))
except StopIteration:
except StopIteration as e:
raise InvalidLayoutError(
"Invalid layout. The layout does not contain any Window object."
)
) from e
else:
self.focus(focused_element)

Expand Down