add backtrace

This commit is contained in:
Peter Zhang 2024-11-01 10:56:20 +08:00
parent 09696fee69
commit 09bf7471b9
3 changed files with 14 additions and 3 deletions

1
Cargo.lock generated
View File

@ -7327,6 +7327,7 @@ name = "storage-async"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"backtrace",
"eth2_ssz", "eth2_ssz",
"shared_types", "shared_types",
"storage", "storage",

View File

@ -10,4 +10,5 @@ storage = { path = "../storage" }
task_executor = { path = "../../common/task_executor" } task_executor = { path = "../../common/task_executor" }
tokio = { version = "1.19.2", features = ["sync"] } tokio = { version = "1.19.2", features = ["sync"] }
tracing = "0.1.35" tracing = "0.1.35"
eth2_ssz = "0.4.0" eth2_ssz = "0.4.0"
backtrace = "0.3"

View File

@ -2,6 +2,7 @@
extern crate tracing; extern crate tracing;
use anyhow::bail; use anyhow::bail;
use backtrace::Backtrace;
use shared_types::{ use shared_types::{
Chunk, ChunkArray, ChunkArrayWithProof, DataRoot, FlowProof, FlowRangeProof, Transaction, Chunk, ChunkArray, ChunkArrayWithProof, DataRoot, FlowProof, FlowRangeProof, Transaction,
}; };
@ -148,8 +149,16 @@ impl Store {
WORKER_TASK_NAME, WORKER_TASK_NAME,
); );
rx.await rx.await.unwrap_or_else(|_| {
.unwrap_or_else(|_| bail!(error::Error::Custom("Receiver error".to_string()))) let mut backtrace = Backtrace::new();
let mut frames = backtrace.frames().to_vec();
if frames.len() > 3 {
frames.drain(0..); //Remove the first 3 unnecessary frames to simplify// backtrace
backtrace = frames.into();
Some(format!("{:?}", backtrace));
}
bail!(error::Error::Custom("Receiver error".to_string()))
})
} }
// FIXME(zz): Refactor the lock and async call here. // FIXME(zz): Refactor the lock and async call here.