From 54cec4a8e02bf73751c16538059d43a465d14541 Mon Sep 17 00:00:00 2001 From: deboard Date: Tue, 2 Jan 2024 17:44:27 -0500 Subject: [PATCH 1/5] issue 2561, send all [bat error]s to stderr in default_error_handler match default. --- src/error.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 007737b0..649ca880 100644 --- a/src/error.rs +++ b/src/error.rs @@ -67,7 +67,9 @@ 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(); } }; } From 6ea3ac71d71d88be64282dbba1dbf5cbfe388a76 Mon Sep 17 00:00:00 2001 From: deboard Date: Tue, 2 Jan 2024 17:44:27 -0500 Subject: [PATCH 2/5] issue 2561, send all [bat error]s to stderr in default_error_handler match default. --- CHANGELOG.md | 2 +- src/error.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfc4c4dd..1d2e41a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Features ## Bugfixes - +- issue 2561, send all [bat error]s to stderr in default_error_handler match default. - Fix `NO_COLOR` support, see #2767 (@acuteenvy) ## Other diff --git a/src/error.rs b/src/error.rs index 007737b0..24c1409f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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(); } }; } From ed6aad7835428525d37aa276f59c58394f36496a Mon Sep 17 00:00:00 2001 From: deboard Date: Fri, 5 Jan 2024 23:20:47 -0500 Subject: [PATCH 3/5] Add test. --- tests/scripts/stderr1.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 tests/scripts/stderr1.sh diff --git a/tests/scripts/stderr1.sh b/tests/scripts/stderr1.sh new file mode 100755 index 00000000..73abc0d4 --- /dev/null +++ b/tests/scripts/stderr1.sh @@ -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 From 10fd0b70e53b3ad3fa446f54f6d68bbf7a9bb687 Mon Sep 17 00:00:00 2001 From: deboard Date: Mon, 22 Jan 2024 20:06:41 -0500 Subject: [PATCH 4/5] Add integration test. --- tests/integration_tests.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index be70fdca..f034cb1f 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -748,6 +748,17 @@ 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() @@ -1194,6 +1205,10 @@ 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(); From ac4f4b40dfd748cd0d563893d82895e378e7f01e Mon Sep 17 00:00:00 2001 From: deboard Date: Mon, 22 Jan 2024 20:23:20 -0500 Subject: [PATCH 5/5] Ran cargo fmt. --- tests/integration_tests.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index f034cb1f..2cec4275 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -756,7 +756,6 @@ fn bat_error_to_stderr() { .assert() .failure() .stderr(predicate::str::contains("[bat error]")); - } #[test] @@ -1206,8 +1205,7 @@ fn can_print_file_starting_with_cache() { } #[test] -fn send_all_bat_error_to_stderr() { -} +fn send_all_bat_error_to_stderr() {} #[test] fn does_not_print_unwanted_file_named_cache() {