Skip to content

Fix logic in panic printing with no stderr #26463

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

Merged
merged 1 commit into from
Jun 21, 2015
Merged
Changes from all 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
23 changes: 12 additions & 11 deletions src/libstd/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ pub fn on_panic(obj: &(Any+Send), file: &'static str, line: u32) {
None => "Box<Any>",
}
};
let mut err = match Stderr::new() {
Ok(err) => err,
_ => return,
};
let mut err = Stderr::new().ok();
let thread = thread_info::current_thread();
let name = thread.as_ref().and_then(|t| t.name()).unwrap_or("<unnamed>");
let prev = LOCAL_STDERR.with(|s| s.borrow_mut().take());
match prev {
Some(mut stderr) => {
match (prev, err.as_mut()) {
(Some(mut stderr), _) => {
// FIXME: what to do when the thread printing panics?
let _ = writeln!(stderr,
"thread '{}' panicked at '{}', {}:{}\n",
Expand All @@ -52,18 +49,22 @@ pub fn on_panic(obj: &(Any+Send), file: &'static str, line: u32) {
*slot.borrow_mut() = s.take();
});
}
None => {
let _ = writeln!(&mut err, "thread '{}' panicked at '{}', {}:{}",
(None, Some(ref mut err)) => {
let _ = writeln!(err, "thread '{}' panicked at '{}', {}:{}",
name, msg, file, line);
if backtrace::log_enabled() {
let _ = backtrace::write(&mut err);
let _ = backtrace::write(err);
}
}
_ => {}
}

// If this is a double panic, make sure that we printed a backtrace
// for this panic.
if unwind::panicking() && !backtrace::log_enabled() {
let _ = backtrace::write(&mut err);
match err {
Some(ref mut err) if unwind::panicking() && !backtrace::log_enabled() => {
let _ = backtrace::write(err);
}
_ => {}
}
}