ferron/
panic.rs

1fn panic_hook(panic_info: &std::panic::PanicHookInfo) {
2  // Technically, it's "Ferris throwing up their hands", but oh well...
3  eprintln!(
4    r#"
5
6                             +=  +==+  =+
7                        +==+============== +=+
8                    +++ ====================== +++
9                    ==============================
10 ===+  +        ===+==============================+===        +  +===
11=====+ ==+      +====================================+      +== +=====
12=========+   ============================================  +===+======
13+========+   +==========================================+  +=========+
14 =========  ++===========================================+  =========
15  ++====== =================....-======-..:================ ======++
16      +===++===============:@@+..-====.*@#..-=============++===+
17       +==================-.=%-..-====.-#-..-=================+
18         ==================:.....-====-....:==================
19        +======--=================:...:==============--======+
20         +======-------==========:.....:========-------=====+
21          +======---  -------------------------=   ---=====+
22            ===== ---                              -- =====
23             +===+                                   +===+
24               ===                                   ===
25
26
27                      S A D   F E R R I S   : (
28
29
30Oh no... Your Ferron web server just crashed...
31"#
32  );
33
34  let payload = panic_info.payload_as_str();
35  eprintln!(
36    "{} (at {})",
37    payload.unwrap_or("<unknown crash>"),
38    panic_info.location().unwrap_or(std::panic::Location::caller())
39  );
40
41  eprintln!();
42  eprintln!("Backtrace:");
43
44  let backtrace = backtrace::Backtrace::new();
45  for frame in backtrace.frames() {
46    let symbols = frame.symbols();
47    if symbols.is_empty() {
48      eprintln!("  at ({:?})", frame.ip());
49    } else {
50      for symbol in symbols {
51        let src_line = symbol
52          .filename()
53          .and_then(|f| symbol.lineno().map(|l| format!("{}:{}", f.display(), l)));
54        eprintln!(
55          "  at {}{}",
56          symbol.name().map(|n| n.to_string()).unwrap_or("<unknown>".to_string()),
57          src_line.map(|l| format!(" ({})", l)).unwrap_or_default()
58        );
59      }
60    }
61  }
62
63  eprintln!();
64  eprintln!("If you believe it's a bug, please report it at https://github.com/ferronweb/ferron/issues/new");
65  eprintln!(
66    "Also, consider sharing the backtrace above, and the version information (you can get it by running `ferron -V`)."
67  )
68}
69
70/// Installs a panic hook
71pub fn install_panic_hook() {
72  if !shadow_rs::is_debug() {
73    std::panic::set_hook(Box::new(panic_hook));
74  }
75}