aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2024-02-17 21:21:37 +0100
committerMatěj Cepl <mcepl@cepl.eu>2024-02-26 12:07:57 +0100
commit2c7dd0cd901aba53f7fef3705ed242ac3850fe16 (patch)
treeb67b7433d21d9c31e8c10aa3dab238d00399a111
parent6b0e9fe0773f05fdf844b574f0f28df3961f60ab (diff)
downloadepy-devel.tar.gz
Don't crash on epy -r when stdout is filtered and interrupted.HEADdevelBrokenPipeError
E.g., epy -r|head threw ugly traceback completely unnecessarily.
-rw-r--r--src/epy_reader/cli.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/epy_reader/cli.py b/src/epy_reader/cli.py
index e43b51c..e604b8f 100644
--- a/src/epy_reader/cli.py
+++ b/src/epy_reader/cli.py
@@ -69,12 +69,16 @@ def print_reading_history(state: State) -> None:
dig = len(str(len(library_items) + 1))
tcols = termc - dig - 2
for n, item in enumerate(library_items):
- print(
- "{} {}".format(
- str(n + 1).rjust(dig),
- truncate(str(item), "...", tcols, tcols - 3),
+ try:
+ print(
+ "{} {}".format(
+ str(n + 1).rjust(dig),
+ truncate(str(item), "...", tcols, tcols - 3),
+ )
)
- )
+ except BrokenPipeError:
+ # Happens when output of epy is filtered through some pipe, e.g. head
+ break
def parse_cli_args() -> argparse.Namespace: