From 3c2d807905b5386d0308a5687442162e1075f4ae Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 18 Aug 2022 07:45:43 -0400 Subject: [PATCH] pager: catch startup failures on Windows If the user's pager settings are broken, display an error message rather than crash to avoid confusing them. Bug: https://crbug.com/gerrit/16173 Change-Id: Idc0891da783c68f3a96ac53a82781e34e40421fb Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/343437 Reviewed-by: LaMont Jones Tested-by: Mike Frysinger --- pager.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pager.py b/pager.py index 352923d9..438597ef 100644 --- a/pager.py +++ b/pager.py @@ -56,8 +56,11 @@ def _PipePager(pager): global pager_process, old_stdout, old_stderr assert pager_process is None, "Only one active pager process at a time" # Create pager process, piping stdout/err into its stdin - pager_process = subprocess.Popen([pager], stdin=subprocess.PIPE, stdout=sys.stdout, - stderr=sys.stderr) + try: + pager_process = subprocess.Popen([pager], stdin=subprocess.PIPE, stdout=sys.stdout, + stderr=sys.stderr) + except FileNotFoundError: + sys.exit(f'fatal: cannot start pager "{pager}"') old_stdout = sys.stdout old_stderr = sys.stderr sys.stdout = pager_process.stdin