Skip to content

Commit

Permalink
Kill codechain in release mode when EXIT_ON_CRASH is set
Browse files Browse the repository at this point in the history
  • Loading branch information
HoOngEe authored and Seulgi Kim committed Jun 16, 2019
1 parent 8b39d71 commit f9cc715
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions util/panic_hook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ This is a bug. Please report it at:
fn panic_hook(info: &PanicInfo) {
let message = panic_message(info);
eprintln!("{}", message);
exit_on_debug_mode();
exit_on_debug_or_env_set_on_release();
}

fn panic_hook_with_email_alarm(email_alarm: &EmailAlarm, info: &PanicInfo) {
Expand All @@ -54,7 +54,7 @@ fn panic_hook_with_email_alarm(email_alarm: &EmailAlarm, info: &PanicInfo) {

let message_for_email = message.replace("\n", "<br>");
email_alarm.send(&format!("IP: {}<br>{}", ip_addresses, message_for_email));
exit_on_debug_mode();
exit_on_debug_or_env_set_on_release();
}

fn panic_message(info: &PanicInfo) -> String {
Expand Down Expand Up @@ -89,12 +89,16 @@ fn panic_message(info: &PanicInfo) -> String {
}

#[cfg(debug_assertions)]
fn exit_on_debug_mode() {
fn exit_on_debug_or_env_set_on_release() {
std::process::exit(-1);
}

#[cfg(not(debug_assertions))]
fn exit_on_debug_mode() {}
fn exit_on_debug_or_env_set_on_release() {
if (std::env::var("EXIT_ON_CRASH").is_ok()) {
std::process::exit(-1);
}
}

fn get_ip_addresses() -> String {
match my_internet_ip::get() {
Expand Down

0 comments on commit f9cc715

Please sign in to comment.