diff --git a/src/main.rs b/src/main.rs index 46007b1..2cc5628 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,13 +78,7 @@ fn main() { Err(valgrind::Error::ValgrindFailure(output)) if output.contains("main thread stack using the --main-stacksize= flag") => { - let error = "Error".red().bold(); - let info = "Info".cyan().bold(); - eprintln!("{error:>12}: looks like the program overflowed its stack"); - eprintln!("{info:>12}: valgrind says:"); - output - .lines() - .for_each(|line| eprintln!(" {line}")); + output::display_stack_overflow(&output); 134 // default exit code for stack overflows } Err(e) => { diff --git a/src/output.rs b/src/output.rs index 2e3b095..f7288e6 100644 --- a/src/output.rs +++ b/src/output.rs @@ -68,3 +68,14 @@ fn display_stack_trace(msg: &str, stack: &valgrind::xml::Stack) { .iter() .for_each(|frame| eprintln!(" at {frame}")); } + +/// Write out an error message for describing the stack overflow message. +pub fn display_stack_overflow(output: &str) { + let error = "Error".red().bold(); + let info = "Info".cyan().bold(); + eprintln!("{error:>12}: looks like the program overflowed its stack"); + eprintln!("{info:>12}: valgrind says:"); + output + .lines() + .for_each(|line| eprintln!(" {line}")); +}