Skip to content

Commit

Permalink
Clean up map_err
Browse files Browse the repository at this point in the history
  • Loading branch information
mullr committed Jun 17, 2024
1 parent 5712d42 commit 8958237
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
31 changes: 11 additions & 20 deletions client-libraries/python/auxon-sdk/src/ingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ impl IngestClient {
timeline_attrs: &Bound<pyo3::types::PyDict>,
) -> Result<(), PyErr> {
let attrs = py_dict_to_attr_vec(timeline_attrs)?;
self.rt
.block_on(
self.client
.send_timeline_attrs(name, attrs.iter().map(|(k, v)| (k.as_str(), v.clone()))),
)
.map_err(SdkError::from)?;
self.rt.block_on(
self.client
.send_timeline_attrs(name, attrs.iter().map(|(k, v)| (k.as_str(), v.clone()))),
)?;

Ok(())
}
Expand All @@ -54,29 +52,22 @@ impl IngestClient {
) -> Result<(), PyErr> {
let attrs = py_dict_to_attr_vec(event_attrs)?;

self.rt
.block_on(self.client.send_event(
name,
ordering,
attrs.iter().map(|(k, v)| (k.as_str(), v.clone())),
))
.map_err(SdkError::from)?;
self.rt.block_on(self.client.send_event(
name,
ordering,
attrs.iter().map(|(k, v)| (k.as_str(), v.clone())),
))?;

Ok(())
}

pub fn flush(&mut self) -> Result<(), PyErr> {
self.rt
.block_on(self.client.flush())
.map_err(SdkError::from)?;
self.rt.block_on(self.client.flush())?;
Ok(())
}

pub fn status(&mut self) -> Result<IngestStatus, PyErr> {
let status = self
.rt
.block_on(self.client.status())
.map_err(SdkError::from)?;
let status = self.rt.block_on(self.client.status())?;
Ok(status)
}
}
Expand Down
7 changes: 7 additions & 0 deletions client-libraries/rust/src/ingest_client/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,10 @@ pub enum DynamicIngestError {
#[error("Invalid state: a timeline must be bound before submitting events")]
NoBoundTimeline,
}

#[cfg(feature = "pyo3")]
impl From<DynamicIngestError> for pyo3::PyErr {
fn from(value: DynamicIngestError) -> Self {
pyo3::exceptions::PyValueError::new_err(value.to_string())
}
}

0 comments on commit 8958237

Please sign in to comment.