Moved err crate

This commit is contained in:
Dominik Werder
2024-11-07 18:26:02 +01:00
parent 8fd7e72796
commit 2f89c969cd
124 changed files with 191 additions and 738 deletions

View File

@@ -11,6 +11,7 @@ use crate::ServiceSharedResources;
use bytes::BufMut;
use bytes::Bytes;
use bytes::BytesMut;
use daqbuf_err as err;
use disk::merge::mergedblobsfromremotes::MergedBlobsFromRemotes;
use futures_util::Stream;
use futures_util::StreamExt;

View File

@@ -3,6 +3,7 @@ use crate::err::Error;
use crate::requests::accepts_json_or_all;
use crate::ReqCtx;
use crate::ServiceSharedResources;
use daqbuf_err as err;
use dbconn::worker::PgQueue;
use err::ToPublicError;
use http::Method;

View File

@@ -5,6 +5,7 @@ use crate::requests::accepts_json_framed;
use crate::requests::accepts_json_or_all;
use crate::requests::accepts_octets;
use crate::ServiceSharedResources;
use daqbuf_err as err;
use dbconn::worker::PgQueue;
use err::thiserror;
use err::ThisError;
@@ -55,7 +56,7 @@ pub enum Error {
EventsCbor(#[from] streams::plaineventscbor::Error),
EventsJson(#[from] streams::plaineventsjson::Error),
ServerError,
BinnedStream(::err::Error),
BinnedStream(err::Error),
TimebinnedJson(#[from] streams::timebinnedjson::Error),
}

View File

@@ -2,6 +2,7 @@ use crate::bodystream::response;
use async_channel::Receiver;
use async_channel::Sender;
use bytes::Bytes;
use daqbuf_err as err;
use err::thiserror;
use err::PublicError;
use err::ThisError;

View File

@@ -1,6 +1,7 @@
use crate::response;
use crate::ReqCtx;
use crate::ServiceSharedResources;
use daqbuf_err as err;
use err::thiserror;
use err::PublicError;
use err::ThisError;

View File

@@ -6,6 +6,7 @@ use crate::response;
use crate::ServiceSharedResources;
use bytes::Bytes;
use bytes::BytesMut;
use daqbuf_err as err;
use dbconn::worker::PgQueue;
use err::thiserror;
use err::ThisError;

View File

@@ -1,4 +1,5 @@
use crate::err::Error;
use daqbuf_err as err;
use err::ToPublicError;
use http::Response;
use http::StatusCode;
@@ -26,7 +27,7 @@ impl ToPublicResponse for Error {
}
}
impl ToPublicResponse for ::err::Error {
impl ToPublicResponse for daqbuf_err::Error {
fn to_public_response(&self) -> StreamResponse {
use err::Reason;
let e = self.to_public_error();

View File

@@ -48,7 +48,7 @@ pub enum Error {
Http(crate::Error),
HttpCrate(http::Error),
// TODO create dedicated error type for query parsing
BadQuery(err::Error),
BadQuery(daqbuf_err::Error),
MissingBackend,
MissingScalarType,
MissingShape,
@@ -56,12 +56,12 @@ pub enum Error {
MissingEdge,
MissingTimerange,
Uri(netpod::UriError),
ChannelConfigQuery(err::Error),
ChannelConfigQuery(daqbuf_err::Error),
ExpectScyllaBackend,
Pg(dbconn::pg::Error),
Scylla(String),
Join,
OtherErr(err::Error),
OtherErr(daqbuf_err::Error),
PgWorker(dbconn::worker::Error),
Async(netpod::AsyncChannelError),
ChannelConfig(dbconn::channelconfig::Error),
@@ -102,7 +102,7 @@ impl fmt::Display for Error {
}
}
fn other_err_error(e: err::Error) -> Error {
fn other_err_error(e: daqbuf_err::Error) -> Error {
Error::OtherErr(e)
}
@@ -446,7 +446,7 @@ pub struct ChannelsWithTypeQuery {
}
impl FromUrl for ChannelsWithTypeQuery {
type Error = err::Error;
type Error = daqbuf_err::Error;
fn from_url(url: &Url) -> Result<Self, Self::Error> {
let pairs = get_url_query_pairs(url);
@@ -456,12 +456,12 @@ impl FromUrl for ChannelsWithTypeQuery {
fn from_pairs(pairs: &BTreeMap<String, String>) -> Result<Self, Self::Error> {
let s = pairs
.get("scalar_type")
.ok_or_else(|| err::Error::with_public_msg_no_trace("missing scalar_type"))?;
.ok_or_else(|| daqbuf_err::Error::with_public_msg_no_trace("missing scalar_type"))?;
//let scalar_type = ScalarType::from_bsread_str(s)?;
let scalar_type: ScalarType = serde_json::from_str(&format!("\"{s}\""))?;
let s = pairs
.get("shape")
.ok_or_else(|| err::Error::with_public_msg_no_trace("missing shape"))?;
.ok_or_else(|| daqbuf_err::Error::with_public_msg_no_trace("missing shape"))?;
let shape = Shape::from_dims_str(s)?;
Ok(Self { scalar_type, shape })
}
@@ -484,29 +484,29 @@ fn bool_false(x: &bool) -> bool {
}
impl FromUrl for ScyllaChannelEventSeriesIdQuery {
type Error = err::Error;
type Error = daqbuf_err::Error;
fn from_url(url: &Url) -> Result<Self, err::Error> {
fn from_url(url: &Url) -> Result<Self, daqbuf_err::Error> {
let pairs = get_url_query_pairs(url);
Self::from_pairs(&pairs)
}
fn from_pairs(pairs: &BTreeMap<String, String>) -> Result<Self, err::Error> {
fn from_pairs(pairs: &BTreeMap<String, String>) -> Result<Self, daqbuf_err::Error> {
let backend = pairs
.get("backend")
.ok_or_else(|| err::Error::with_public_msg_no_trace("missing backend"))?
.ok_or_else(|| daqbuf_err::Error::with_public_msg_no_trace("missing backend"))?
.into();
let name = pairs
.get("channelName")
.ok_or_else(|| err::Error::with_public_msg_no_trace("missing channelName"))?
.ok_or_else(|| daqbuf_err::Error::with_public_msg_no_trace("missing channelName"))?
.into();
let s = pairs
.get("scalarType")
.ok_or_else(|| err::Error::with_public_msg_no_trace("missing scalarType"))?;
.ok_or_else(|| daqbuf_err::Error::with_public_msg_no_trace("missing scalarType"))?;
let scalar_type: ScalarType = serde_json::from_str(&format!("\"{s}\""))?;
let s = pairs
.get("shape")
.ok_or_else(|| err::Error::with_public_msg_no_trace("missing shape"))?;
.ok_or_else(|| daqbuf_err::Error::with_public_msg_no_trace("missing shape"))?;
let shape = Shape::from_dims_str(s)?;
let do_create = pairs.get("doCreate").map_or("false", |x| x.as_str()) == "true";
Ok(Self {
@@ -535,25 +535,25 @@ pub struct ScyllaChannelsActiveQuery {
}
impl FromUrl for ScyllaChannelsActiveQuery {
type Error = err::Error;
type Error = daqbuf_err::Error;
fn from_url(url: &Url) -> Result<Self, err::Error> {
fn from_url(url: &Url) -> Result<Self, daqbuf_err::Error> {
let pairs = get_url_query_pairs(url);
Self::from_pairs(&pairs)
}
fn from_pairs(pairs: &BTreeMap<String, String>) -> Result<Self, err::Error> {
fn from_pairs(pairs: &BTreeMap<String, String>) -> Result<Self, daqbuf_err::Error> {
let s = pairs
.get("tsedge")
.ok_or_else(|| err::Error::with_public_msg_no_trace("missing tsedge"))?;
.ok_or_else(|| daqbuf_err::Error::with_public_msg_no_trace("missing tsedge"))?;
let tsedge: u64 = s.parse()?;
let s = pairs
.get("shapeKind")
.ok_or_else(|| err::Error::with_public_msg_no_trace("missing shapeKind"))?;
.ok_or_else(|| daqbuf_err::Error::with_public_msg_no_trace("missing shapeKind"))?;
let shape_kind: u32 = s.parse()?;
let s = pairs
.get("scalarType")
.ok_or_else(|| err::Error::with_public_msg_no_trace("missing scalarType"))?;
.ok_or_else(|| daqbuf_err::Error::with_public_msg_no_trace("missing scalarType"))?;
let scalar_type: ScalarType = serde_json::from_str(&format!("\"{s}\""))?;
info!("parsed scalar type inp: {s:?} val: {scalar_type:?}");
Ok(Self {
@@ -643,7 +643,7 @@ pub struct IocForChannelQuery {
}
impl FromUrl for IocForChannelQuery {
type Error = err::Error;
type Error = daqbuf_err::Error;
fn from_url(url: &Url) -> Result<Self, Self::Error> {
let pairs = get_url_query_pairs(url);
@@ -653,11 +653,11 @@ impl FromUrl for IocForChannelQuery {
fn from_pairs(pairs: &BTreeMap<String, String>) -> Result<Self, Self::Error> {
let backend = pairs
.get("backend")
.ok_or_else(|| err::Error::with_public_msg_no_trace("missing backend"))?
.ok_or_else(|| daqbuf_err::Error::with_public_msg_no_trace("missing backend"))?
.into();
let name = pairs
.get("channelName")
.ok_or_else(|| err::Error::with_public_msg_no_trace("missing channelName"))?
.ok_or_else(|| daqbuf_err::Error::with_public_msg_no_trace("missing channelName"))?
.into();
Ok(Self { backend, name })
}

View File

@@ -1,3 +1,4 @@
use daqbuf_err as err;
use err::ToPublicError;
use serde::Deserialize;
use serde::Serialize;
@@ -28,7 +29,7 @@ impl Error {
self.0.msg()
}
pub fn reason(&self) -> Option<::err::Reason> {
pub fn reason(&self) -> Option<err::Reason> {
self.0.reason()
}
@@ -84,7 +85,7 @@ where
T: ToString,
{
fn from(x: T) -> Self {
Self(::err::Error::from_string(x))
Self(err::Error::from_string(x))
}
}

View File

@@ -16,8 +16,9 @@ pub mod settings;
use crate::bodystream::response;
use crate::err::Error;
use ::err::thiserror;
use ::err::ThisError;
use daqbuf_err;
use daqbuf_err::thiserror;
use daqbuf_err::ThisError;
use dbconn::worker::PgQueue;
use dbconn::worker::PgWorker;
use futures_util::Future;
@@ -63,7 +64,7 @@ use tracing::Instrument;
#[derive(Debug, ThisError, Serialize, Deserialize)]
#[cstm(name = "Retrieval")]
pub enum RetrievalError {
Error(#[from] ::err::Error),
Error(#[from] daqbuf_err::Error),
Error2(#[from] crate::err::Error),
TextError(String),
#[serde(skip)]
@@ -99,9 +100,9 @@ where
}
}
impl ::err::ToErr for RetrievalError {
fn to_err(self) -> ::err::Error {
::err::Error::with_msg_no_trace(self.to_string())
impl daqbuf_err::ToErr for RetrievalError {
fn to_err(self) -> daqbuf_err::Error {
daqbuf_err::Error::with_msg_no_trace(self.to_string())
}
}

View File

@@ -233,14 +233,14 @@ impl StatusNodesRecursive {
for (tag, sr) in all {
match sr {
Ok(sr) => {
let s: Result<NodeStatus, _> = serde_json::from_value(sr.val).map_err(err::Error::from);
let s: Result<NodeStatus, _> = serde_json::from_value(sr.val).map_err(daqbuf_err::Error::from);
let sub = NodeStatusSub { url: tag.0, status: s };
subs.push_back(sub);
}
Err(e) => {
let sub = NodeStatusSub {
url: tag.0,
status: Err(err::Error::from(e)),
status: Err(daqbuf_err::Error::from(e)),
};
subs.push_back(sub);
}

View File

@@ -889,24 +889,24 @@ struct LocalMap {
}
pub trait ErrConv<T> {
fn err_conv(self) -> Result<T, err::Error>;
fn err_conv(self) -> Result<T, daqbuf_err::Error>;
}
impl<T> ErrConv<T> for Result<T, scylla::transport::errors::NewSessionError> {
fn err_conv(self) -> Result<T, err::Error> {
self.map_err(|e| err::Error::with_msg_no_trace(format!("{e:?}")))
fn err_conv(self) -> Result<T, daqbuf_err::Error> {
self.map_err(|e| daqbuf_err::Error::with_msg_no_trace(format!("{e:?}")))
}
}
impl<T> ErrConv<T> for Result<T, scylla::transport::errors::QueryError> {
fn err_conv(self) -> Result<T, err::Error> {
self.map_err(|e| err::Error::with_msg_no_trace(format!("{e:?}")))
fn err_conv(self) -> Result<T, daqbuf_err::Error> {
self.map_err(|e| daqbuf_err::Error::with_msg_no_trace(format!("{e:?}")))
}
}
impl<T> ErrConv<T> for Result<T, scylla::transport::query_result::RowsExpectedError> {
fn err_conv(self) -> Result<T, err::Error> {
self.map_err(|e| err::Error::with_msg_no_trace(format!("{e:?}")))
fn err_conv(self) -> Result<T, daqbuf_err::Error> {
self.map_err(|e| daqbuf_err::Error::with_msg_no_trace(format!("{e:?}")))
}
}