diff --git a/CHANGELOG.md b/CHANGELOG.md index d8d93805..3e8fad14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Improve native man pages and command help syntax highlighting by stripping overstriking, see #3517 (@akirk) ## Bugfixes +- Report error when pager is missing instead of silently falling back, see #3588 (@IMaloney) - Fix crash with BusyBox `less` on Windows, see #3527 (@Anchal-T) - Fix `bat cache --help` failing with 'unexpected argument' error, see #3580 and #3560 (@NORMAL-EX) - `--help` now correctly honors `--pager=builtin`. See #3516 (@keith-hall) diff --git a/src/output.rs b/src/output.rs index e5c8a654..64ef2f15 100644 --- a/src/output.rs +++ b/src/output.rs @@ -105,6 +105,10 @@ impl OutputType { let resolved_path = match grep_cli::resolve_binary(&pager.bin) { Ok(path) => path, Err(_) => { + crate::bat_warning!( + "Pager '{}' not found, outputting to stdout instead", + pager.bin.to_string_lossy() + ); return Ok(OutputType::stdout()); } }; @@ -174,7 +178,13 @@ impl OutputType { Ok(p.stdin(Stdio::piped()) .spawn() .map(OutputType::Pager) - .unwrap_or_else(|_| OutputType::stdout())) + .unwrap_or_else(|_| { + crate::bat_warning!( + "Pager '{}' not found, outputting to stdout instead", + &pager.bin + ); + OutputType::stdout() + })) } pub(crate) fn stdout() -> Self { diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index da8b21eb..b6de86ee 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1425,6 +1425,21 @@ fn pager_failed_to_parse() { .stderr(predicate::str::contains("Could not parse pager command")); } +#[test] +#[serial] +fn pager_missing_warning() { + bat() + .env("BAT_PAGER", "nonexistent-pager-xyz-missing") + .arg("--paging=always") + .arg("test.txt") + .assert() + .success() + .stderr(predicate::str::contains("[bat warning]")) + .stderr(predicate::str::contains("not found")) + .stderr(predicate::str::contains("nonexistent-pager-xyz-missing")) + .stdout(predicate::str::contains("hello world\n")); +} + #[test] #[serial] fn env_var_bat_paging() {