Skip to content

Commit f9cc715

Browse files
HoOngEeSeulgi Kim
authored andcommitted
Kill codechain in release mode when EXIT_ON_CRASH is set
1 parent 8b39d71 commit f9cc715

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

util/panic_hook/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ This is a bug. Please report it at:
4444
fn panic_hook(info: &PanicInfo) {
4545
let message = panic_message(info);
4646
eprintln!("{}", message);
47-
exit_on_debug_mode();
47+
exit_on_debug_or_env_set_on_release();
4848
}
4949

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

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

6060
fn panic_message(info: &PanicInfo) -> String {
@@ -89,12 +89,16 @@ fn panic_message(info: &PanicInfo) -> String {
8989
}
9090

9191
#[cfg(debug_assertions)]
92-
fn exit_on_debug_mode() {
92+
fn exit_on_debug_or_env_set_on_release() {
9393
std::process::exit(-1);
9494
}
9595

9696
#[cfg(not(debug_assertions))]
97-
fn exit_on_debug_mode() {}
97+
fn exit_on_debug_or_env_set_on_release() {
98+
if (std::env::var("EXIT_ON_CRASH").is_ok()) {
99+
std::process::exit(-1);
100+
}
101+
}
98102

99103
fn get_ip_addresses() -> String {
100104
match my_internet_ip::get() {

0 commit comments

Comments
 (0)