From b3877a551587011b91bee8f3edabd084fc9d7d35 Mon Sep 17 00:00:00 2001 From: Neil Macneale IV Date: Wed, 27 Aug 2025 16:30:48 -0700 Subject: [PATCH] Handle bogus pager gracefully --- go/store/util/outputpager/page_output.go | 17 ++++++++++------- integration-tests/bats/pager.bats | 10 ++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/go/store/util/outputpager/page_output.go b/go/store/util/outputpager/page_output.go index 922d73ffc2..056e7fa93a 100644 --- a/go/store/util/outputpager/page_output.go +++ b/go/store/util/outputpager/page_output.go @@ -68,15 +68,18 @@ func Start() *Pager { parts := strings.Fields(doltPager) pagerPath, err = exec.LookPath(parts[0]) if err != nil { - d.Chk.NoError(err) - } - if len(parts) > 1 { - cmd = exec.Command(pagerPath, parts[1:]...) + // If the specified pager is not found, print an error and fall back to less or more + fmt.Fprintf(os.Stderr, "warning: specified pager '%s' not found, falling back to less or more\n", parts[0]) } else { - cmd = exec.Command(pagerPath) + if len(parts) > 1 { + cmd = exec.Command(pagerPath, parts[1:]...) + } else { + cmd = exec.Command(pagerPath) + } } - } else { - // Fall back to less or more if DOLT_PAGER is not set + } + + if cmd == nil { pagerPath, err = exec.LookPath("less") if err != nil { pagerPath, err = exec.LookPath("more") diff --git a/integration-tests/bats/pager.bats b/integration-tests/bats/pager.bats index 1de0c4b7c1..126afc613c 100644 --- a/integration-tests/bats/pager.bats +++ b/integration-tests/bats/pager.bats @@ -36,3 +36,13 @@ export NO_COLOR=1 [[ ! "$output" =~ "commit 17 abc" ]] || false [ "${#lines[@]}" -eq 3 ] } + +# bats test_tags=no_lambda +@test "pager: gracefully exit when pager doesn't exist" { + skiponwindows "Need to install expect and make this script work on windows." + export DOLT_PAGER="foobar" + + run expect $BATS_TEST_DIRNAME/pager.expect + [ "$status" -eq 0 ] + [[ "$output" =~ "warning: specified pager 'foobar' not found, falling back to less or more" ]] || false +}