Skip to content

Commit

Permalink
Don't crash on epy -r when stdout is filtered and interrupted.
Browse files Browse the repository at this point in the history
E.g., epy -r|head threw ugly traceback completely unnecessarily.
  • Loading branch information
mcepl committed Feb 26, 2024
1 parent 6b0e9fe commit 2c7dd0c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/epy_reader/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2c7dd0c

Please sign in to comment.