1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-02 11:22:30 +01:00

Send errors to stderr (#3336)

* fix: send errors to stderr by default (#2561)

Closes #2561

* chore: add changelog entry

* chore: change PR id

* chore: add github username

* chore: cargo fmt...

* chore: move changelog line to bugfixes
This commit is contained in:
Jerry
2025-07-08 23:42:22 +05:00
committed by GitHub
parent cf7631d469
commit 9776ebfa0f
3 changed files with 18 additions and 1 deletions

View File

@@ -14,6 +14,7 @@
- Make highlight tests fail when new syntaxes don't have fixtures PR #3255 (@dan-hipschman) - Make highlight tests fail when new syntaxes don't have fixtures PR #3255 (@dan-hipschman)
- Fix crash for multibyte characters in file path, see issue #3230 and PR #3245 (@HSM95) - Fix crash for multibyte characters in file path, see issue #3230 and PR #3245 (@HSM95)
- Add missing mappings for various bash/zsh files, see PR #3262 (@AdamGaskins) - Add missing mappings for various bash/zsh files, see PR #3262 (@AdamGaskins)
- Send all bat errors to stderr by default, see #3336 (@JerryImMouse)
## Other ## Other

View File

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

View File

@@ -450,6 +450,16 @@ fn stdin_to_stdout_cycle() -> io::Result<()> {
Ok(()) Ok(())
} }
#[cfg(unix)]
#[test]
fn bat_error_to_stderr() {
bat()
.arg("/tmp")
.assert()
.failure()
.stderr(predicate::str::contains("[bat error]"));
}
#[cfg(unix)] #[cfg(unix)]
#[test] #[test]
fn no_args_doesnt_break() { fn no_args_doesnt_break() {