Skip to content

Commit f5af7d3

Browse files
committed
Added broader exception handling when enabling clipboard functionality via pyperclip.
1 parent bef3c75 commit f5af7d3

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.3.4 (TBD, 2021)
2+
* Enhancements
3+
* Added broader exception handling when enabling clipboard functionality via `pyperclip`.
4+
15
## 2.3.3 (November 29, 2021)
26
* Enhancements
37
* Added clearer exception handling to `BorderedTable` and `SimpleTable`.

cmd2/clipboard.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@
99
import pyperclip # type: ignore[import]
1010

1111
# noinspection PyProtectedMember
12-
from pyperclip import (
13-
PyperclipException,
14-
)
1512

1613
# Can we access the clipboard? Should always be true on Windows and Mac, but only sometimes on Linux
14+
# noinspection PyBroadException
1715
try:
1816
# Try getting the contents of the clipboard
1917
_ = pyperclip.paste()
20-
except (PyperclipException, FileNotFoundError, ValueError):
21-
# NOTE: FileNotFoundError is for Windows Subsystem for Linux (WSL) when Windows paths are removed from $PATH
22-
# NOTE: ValueError is for headless Linux systems without Gtk installed
18+
19+
# pyperclip raises at least the following types of exceptions. To be safe, just catch all Exceptions.
20+
# FileNotFoundError on Windows Subsystem for Linux (WSL) when Windows paths are removed from $PATH
21+
# ValueError for headless Linux systems without Gtk installed
22+
# AssertionError can be raised by paste_klipper().
23+
# PyperclipException for pyperclip-specific exceptions
24+
except Exception:
2325
can_clip = False
2426
else:
2527
can_clip = True

cmd2/cmd2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4086,7 +4086,7 @@ def do_shell(self, args: argparse.Namespace) -> None:
40864086
self.last_result = proc.returncode
40874087

40884088
# If the process was stopped by Ctrl-C, then inform the caller by raising a KeyboardInterrupt.
4089-
# This is to support things like stop_on_keyboard_interrupt in run_cmds_plus_hooks().
4089+
# This is to support things like stop_on_keyboard_interrupt in runcmds_plus_hooks().
40904090
if proc.returncode == ctrl_c_ret_code:
40914091
self._raise_keyboard_interrupt()
40924092

0 commit comments

Comments
 (0)