RetStreamExt to pass only first error
This commit is contained in:
@@ -9,7 +9,9 @@ hyper = { version = "0.14", features = ["http1", "http2", "client", "server", "t
|
||||
http = "0.2"
|
||||
tokio = { version = "1.5.0", features = ["rt-multi-thread", "io-util", "net", "time", "sync", "fs"] }
|
||||
backtrace = "0.3.56"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
bincode = "1.3.3"
|
||||
async-channel = "1.6"
|
||||
chrono = { version = "0.4.19", features = ["serde"] }
|
||||
nom = "6.1.2"
|
||||
|
||||
@@ -3,6 +3,7 @@ Error handling and reporting.
|
||||
*/
|
||||
|
||||
use nom::error::ErrorKind;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Debug;
|
||||
use std::net::AddrParseError;
|
||||
use std::num::ParseIntError;
|
||||
@@ -12,16 +13,18 @@ use tokio::task::JoinError;
|
||||
/**
|
||||
The common error type for this application.
|
||||
*/
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Error {
|
||||
msg: String,
|
||||
trace: backtrace::Backtrace,
|
||||
#[serde(skip)]
|
||||
trace: Option<backtrace::Backtrace>,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub fn with_msg<S: Into<String>>(s: S) -> Self {
|
||||
Self {
|
||||
msg: s.into(),
|
||||
trace: backtrace::Backtrace::new(),
|
||||
trace: Some(backtrace::Backtrace::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,33 +33,39 @@ impl std::fmt::Debug for Error {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
use std::io::Write;
|
||||
let mut buf = vec![];
|
||||
for fr in self.trace.frames() {
|
||||
for sy in fr.symbols() {
|
||||
let is_ours = match sy.filename() {
|
||||
None => false,
|
||||
Some(s) => s.to_str().unwrap().contains("dev/daqbuffer"),
|
||||
};
|
||||
let name = match sy.name() {
|
||||
Some(k) => k.to_string(),
|
||||
_ => "[err]".into(),
|
||||
};
|
||||
let filename = match sy.filename() {
|
||||
Some(k) => match k.to_str() {
|
||||
Some(k) => k,
|
||||
_ => "[err]",
|
||||
},
|
||||
_ => "[err]",
|
||||
};
|
||||
let lineno = match sy.lineno() {
|
||||
Some(k) => k,
|
||||
_ => 0,
|
||||
};
|
||||
if is_ours {
|
||||
write!(&mut buf, "\n {}\n {} {}", name, filename, lineno).unwrap();
|
||||
match &self.trace {
|
||||
Some(trace) => {
|
||||
for fr in trace.frames() {
|
||||
for sy in fr.symbols() {
|
||||
let is_ours = match sy.filename() {
|
||||
None => false,
|
||||
Some(s) => s.to_str().unwrap().contains("dev/daqbuffer"),
|
||||
};
|
||||
let name = match sy.name() {
|
||||
Some(k) => k.to_string(),
|
||||
_ => "[err]".into(),
|
||||
};
|
||||
let filename = match sy.filename() {
|
||||
Some(k) => match k.to_str() {
|
||||
Some(k) => k,
|
||||
_ => "[err]",
|
||||
},
|
||||
_ => "[err]",
|
||||
};
|
||||
let lineno = match sy.lineno() {
|
||||
Some(k) => k,
|
||||
_ => 0,
|
||||
};
|
||||
if is_ours {
|
||||
write!(&mut buf, "\n {}\n {} {}", name, filename, lineno).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
write!(&mut buf, "NO_TRACE").unwrap();
|
||||
}
|
||||
}
|
||||
//write!(fmt, "Error {} backtrace:\n{:?}", self.msg, self.trace)
|
||||
write!(fmt, "Error {}\nTrace:{}", self.msg, String::from_utf8(buf).unwrap())
|
||||
}
|
||||
}
|
||||
@@ -157,6 +166,12 @@ impl From<JoinError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<bincode::ErrorKind>> for Error {
|
||||
fn from(k: Box<bincode::ErrorKind>) -> Self {
|
||||
Self::with_msg(format!("bincode::ErrorKind {:?}", k))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn todoval<T>() -> T {
|
||||
todo!("TODO todoval")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user