WIP add thiserror, anyhow
This commit is contained in:
1592
.cargo/cargo-lock
1592
.cargo/cargo-lock
File diff suppressed because it is too large
Load Diff
@@ -16,3 +16,5 @@ chrono = { version = "0.4", features = ["serde"] }
|
||||
url = "2.2"
|
||||
regex = "1.5"
|
||||
http = "0.2"
|
||||
thiserror = "1.0"
|
||||
anyhow = "1.0"
|
||||
|
||||
@@ -1,16 +1,60 @@
|
||||
//! Error handling and reporting.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
pub use anyhow;
|
||||
pub use thiserror;
|
||||
|
||||
pub mod bt {
|
||||
pub use backtrace::Backtrace;
|
||||
}
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::array::TryFromSliceError;
|
||||
use std::convert::Infallible;
|
||||
use std::fmt;
|
||||
use std::net::AddrParseError;
|
||||
use std::num::{ParseFloatError, ParseIntError};
|
||||
use std::num::ParseFloatError;
|
||||
use std::num::ParseIntError;
|
||||
use std::string::FromUtf8Error;
|
||||
use std::sync::PoisonError;
|
||||
|
||||
pub mod bt {
|
||||
pub use backtrace::Backtrace;
|
||||
pub type Res2<T> = anyhow::Result<T>;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ErrA {
|
||||
#[error("bad-A")]
|
||||
Bad,
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ErrB {
|
||||
#[error("worse-B")]
|
||||
Worse,
|
||||
#[error("FromArrA")]
|
||||
ErrA(#[from] ErrA),
|
||||
}
|
||||
|
||||
fn f_a() -> Result<u32, ErrA> {
|
||||
Err(ErrA::Bad)
|
||||
}
|
||||
|
||||
fn f_b() -> Result<u32, ErrB> {
|
||||
if true {
|
||||
let res = f_a()?;
|
||||
Ok(res)
|
||||
} else {
|
||||
Err(ErrB::Worse)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn f_c() -> Result<u32, anyhow::Error> {
|
||||
return Ok(f_b()?);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fc() {
|
||||
assert_eq!(f_c().is_ok(), true);
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@@ -378,6 +422,12 @@ impl From<http::header::ToStrError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<anyhow::Error> for Error {
|
||||
fn from(k: anyhow::Error) -> Self {
|
||||
Self::with_msg(format!("{k}"))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PublicError {
|
||||
reason: Option<Reason>,
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::bodystream::ToPublicResponse;
|
||||
use crate::channelconfig::chconf_from_binned;
|
||||
use crate::err::Error;
|
||||
use crate::response_err;
|
||||
use err::anyhow::Context;
|
||||
use http::Method;
|
||||
use http::Request;
|
||||
use http::Response;
|
||||
@@ -30,7 +31,7 @@ async fn binned_json(url: Url, req: Request<Body>, node_config: &NodeConfigCache
|
||||
let chconf = chconf_from_binned(&query, node_config).await?;
|
||||
// Update the series id since we don't require some unique identifier yet.
|
||||
let mut query = query;
|
||||
query.set_series_id(chconf.try_series()?);
|
||||
query.set_series_id(chconf.try_series().context("binned_json")?);
|
||||
let query = query;
|
||||
// ---
|
||||
let span1 = span!(
|
||||
|
||||
@@ -4,6 +4,7 @@ use crate::response;
|
||||
use crate::response_err;
|
||||
use crate::BodyStream;
|
||||
use crate::ToPublicResponse;
|
||||
use err::anyhow::Context;
|
||||
use futures_util::stream;
|
||||
use futures_util::TryStreamExt;
|
||||
use http::Method;
|
||||
@@ -78,7 +79,7 @@ async fn plain_events_binary(
|
||||
info!("plain_events_binary chconf_from_events_v1: {chconf:?}");
|
||||
// Update the series id since we don't require some unique identifier yet.
|
||||
let mut query = query;
|
||||
query.set_series_id(chconf.try_series()?);
|
||||
query.set_series_id(chconf.try_series().context("plain_events_binary")?);
|
||||
let query = query;
|
||||
// ---
|
||||
let _ = query;
|
||||
@@ -103,7 +104,7 @@ async fn plain_events_json(
|
||||
info!("plain_events_json chconf_from_events_v1: {chconf:?}");
|
||||
// Update the series id since we don't require some unique identifier yet.
|
||||
let mut query = query;
|
||||
query.set_series_id(chconf.try_series()?);
|
||||
query.set_series_id(chconf.try_series().context("plain_events_json")?);
|
||||
let query = query;
|
||||
// ---
|
||||
//let query = RawEventsQuery::new(query.channel().clone(), query.range().clone(), AggKind::Plain);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::bodystream::response;
|
||||
use crate::err::Error;
|
||||
use crate::ReqCtx;
|
||||
use err::anyhow::Context;
|
||||
use futures_util::StreamExt;
|
||||
use http::Method;
|
||||
use http::Request;
|
||||
@@ -153,7 +154,7 @@ impl ChannelStatusEvents {
|
||||
nodenet::channelconfig::channel_config(q.range().clone(), q.channel().clone(), node_config).await?;
|
||||
let do_one_before_range = true;
|
||||
let mut stream = scyllaconn::status::StatusStreamScylla::new(
|
||||
chconf.try_series()?,
|
||||
chconf.try_series().context("channel_status")?,
|
||||
q.range().clone(),
|
||||
do_one_before_range,
|
||||
scy,
|
||||
|
||||
@@ -92,3 +92,4 @@ impl Convable for http::Error {}
|
||||
impl Convable for http::header::ToStrError {}
|
||||
impl Convable for hyper::Error {}
|
||||
impl Convable for std::array::TryFromSliceError {}
|
||||
impl Convable for err::anyhow::Error {}
|
||||
|
||||
@@ -13,7 +13,9 @@ use bytes::Bytes;
|
||||
use chrono::DateTime;
|
||||
use chrono::TimeZone;
|
||||
use chrono::Utc;
|
||||
use err::anyhow;
|
||||
use err::Error;
|
||||
use err::Res2;
|
||||
use futures_util::Stream;
|
||||
use futures_util::StreamExt;
|
||||
use range::evrange::NanoRange;
|
||||
@@ -2279,9 +2281,9 @@ pub struct ChConf {
|
||||
}
|
||||
|
||||
impl ChConf {
|
||||
pub fn try_series(&self) -> Result<u64, Error> {
|
||||
pub fn try_series(&self) -> Res2<u64> {
|
||||
self.series
|
||||
.ok_or_else(|| Error::with_msg_no_trace("ChConf without SeriesId"))
|
||||
.ok_or_else(|| anyhow::anyhow!("ChConf without SeriesId {self:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use err::anyhow::Context;
|
||||
use err::Error;
|
||||
use futures_util::Stream;
|
||||
use futures_util::StreamExt;
|
||||
@@ -28,7 +29,7 @@ pub async fn scylla_channel_event_stream(
|
||||
.await
|
||||
.map_err(|e| Error::with_msg_no_trace(format!("{e:?}")))?;
|
||||
let scy = scyllaconn::create_scy_session(scyco).await?;
|
||||
let series = f.try_series()?;
|
||||
let series = f.try_series().context("scylla_channel_event_stream")?;
|
||||
let scalar_type = f.scalar_type;
|
||||
let shape = f.shape;
|
||||
let do_test_stream_error = false;
|
||||
|
||||
Reference in New Issue
Block a user