1pub mod debug;
3mod git;
4
5use std::{io, panic};
6
7#[cfg(test)]
8mod tests {
9 #[test]
10 fn it_works() {
11 assert_eq!(2 + 2, 4);
12 }
13}
14
15pub fn watch<F: 'static>(method: F) where F: debug::SubmitMethod {
18 panic::set_hook(Box::new(move |panic_info| {
19 let mut input = String::new();
20
21 println!("Program crashed unexpectedly! Would you like to submit a report [Y/n]?");
22
23 match io::stdin().read_line(&mut input) {
24 Ok(_) if input.as_str() == "n\n" => return (),
25 _ => {}
26 }
27
28 println!("Please describe briefly what happened.");
29
30 let desc = match io::stdin().read_line(&mut input) {
31 Ok(_) => input.clone(),
32 Err(_) => String::from("Error while describing bug.")
33 };
34
35 let sha = match git::sha() {
36 Some(tree) => tree,
37 None => String::from("None")
38 };
39
40 let dbg = debug::DebugInfo::new (
41 &sha,
42 desc,
43 panic_info.payload().downcast_ref::<&str>().unwrap(),
44 panic_info.location()
45 );
46
47 match method.submit(&dbg) {
48 true => method.submission_succeeded(&dbg),
49 false => method.submission_failed(&dbg)
50 }
51 }));
52}