This commit is contained in:
John DeBoard 2024-05-01 05:26:28 +01:00 committed by GitHub
commit a28d961bc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 1 deletions

View File

@ -10,7 +10,10 @@
## Bugfixes
- Send all bat error messages to stderr, see #2827 (@deboard)
- Fix long file name wrapping in header, see #2835 (@FilipRazek)
-
- Fix `NO_COLOR` support, see #2767 (@acuteenvy)
- Fix handling of inputs with OSC ANSI escape sequences, see #2541 and #2544 (@eth-p)
- Fix handling of inputs with combined ANSI color and attribute sequences, see #2185 and #2856 (@eth-p)

View File

@ -67,7 +67,15 @@ pub fn default_error_handler(error: &Error, output: &mut dyn Write) {
.ok();
}
_ => {
writeln!(output, "{}: {}", Red.paint("[bat error]"), error).ok();
// default - always write [bat error] to stderr
let stderr = std::io::stderr();
writeln!(
&mut stderr.lock(),
"{}: {}",
Red.paint("[bat error]"),
error
)
.ok();
}
};
}

View File

@ -847,6 +847,16 @@ fn env_var_bat_pager_value_bat() {
.stderr(predicate::str::contains("bat as a pager is disallowed"));
}
#[test]
fn bat_error_to_stderr() {
bat()
.env("BAT_PAGER", "bat")
.arg("/tmp")
.assert()
.failure()
.stderr(predicate::str::contains("[bat error]"));
}
#[test]
fn pager_value_bat() {
bat()
@ -1319,6 +1329,9 @@ fn can_print_file_starting_with_cache() {
.stderr("");
}
#[test]
fn send_all_bat_error_to_stderr() {}
#[test]
fn does_not_print_unwanted_file_named_cache() {
bat_with_config().arg("cach").assert().failure();

14
tests/scripts/stderr1.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
## test for issue 2561
OUTPUT=$(mktemp)
BAT=bat
code=$($BAT /tmp 2> $OUTPUT; cat $OUTPUT | grep error; echo $?)
if [[ $code == 1 ]]; then
echo "stderr test fsil"
exit 1
fi
exit 0