1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::sync::OnceLock;
use regex::Regex;
use crate::{Error, Result};
static NAME_BLOCKLIST: OnceLock<Vec<Regex>> = OnceLock::new();
static FILE_BLOCKLIST: OnceLock<Vec<Regex>> = OnceLock::new();
fn get_name_blocklist() -> &'static Vec<Regex> {
NAME_BLOCKLIST.get_or_init(|| {
[
"^___rust_try",
"^__pthread",
"^__clone",
"^<loco_rs::errors::Error as",
"^loco_rs::errors::Error::bt",
/*
"^<?tokio",
"^<?future",
"^<?tower",
"^<?futures",
"^<?hyper",
"^<?axum",
"<F as futures_core",
"^<F as axum::",
"^<?std::panic",
"^<?core::",
"^rust_panic",
"^rayon",
"^rust_begin_unwind",
"^start_thread",
"^call_once",
"^catch_unwind",
*/
]
.iter()
.map(|s| Regex::new(s).unwrap())
.collect::<Vec<_>>()
})
}
fn get_file_blocklist() -> &'static Vec<Regex> {
FILE_BLOCKLIST.get_or_init(|| {
[
"axum-.*$",
"tower-.*$",
"hyper-.*$",
"tokio-.*$",
"futures-.*$",
"^/rustc",
]
.iter()
.map(|s| Regex::new(s).unwrap())
.collect::<Vec<_>>()
})
}
pub fn print_backtrace(bt: &std::backtrace::Backtrace) -> Result<()> {
backtrace_printer::print_backtrace(
&mut std::io::stdout(),
bt,
get_name_blocklist(),
get_file_blocklist(),
)
.map_err(Error::msg)
}