Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue 2561, send all [bat error]s to stderr in default_error_handler #2827

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Features

## Bugfixes

- Send all bat error messages to stderr, see #2827 (@deboard)
- Fix `NO_COLOR` support, see #2767 (@acuteenvy)

## Other
Expand Down
10 changes: 9 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
}
14 changes: 14 additions & 0 deletions tests/scripts/stderr1.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please turn this into a Rust-based integration test. See tests/integration_tests.rs and search for .stderr to see some examples.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script is still here. Can it be removed?