Skip to content

Commit

Permalink
Change e.into() into Box::new(e)
Browse files Browse the repository at this point in the history
For some reason, the former is not Send and that is needed when these
errors are async returned.
  • Loading branch information
rkuris committed Nov 14, 2023
1 parent 57a7774 commit a08d9b2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions firewood/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl<S: ShaleStore<Node> + Send + Sync> DbRev<S> {
// TODO: get first key when start_key is None
self.merkle
.get_iter(start_key, self.header.kv_root)
.map_err(|e| api::Error::InternalError(e.into()))
.map_err(|e| api::Error::InternalError(Box::new(e)))
}

fn flush_dirty(&mut self) -> Option<()> {
Expand Down Expand Up @@ -455,7 +455,7 @@ impl Db {
}

block_in_place(|| Db::new_internal(db_path, cfg.clone()))
.map_err(|e| api::Error::InternalError(e.into()))
.map_err(|e| api::Error::InternalError(Box::new(e)))
}

/// Open a database.
Expand Down
12 changes: 6 additions & 6 deletions firewood/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ impl<'a, S: shale::ShaleStore<node::Node> + Send + Sync> Stream for MerkleKeyVal
let root_node = self
.merkle
.get_node(self.merkle_root)
.map_err(|e| api::Error::InternalError(e.into()))?;
.map_err(|e| api::Error::InternalError(Box::new(e)))?;
let mut last_node = root_node;
let mut parents = vec![];
let leaf = loop {
Expand All @@ -1259,7 +1259,7 @@ impl<'a, S: shale::ShaleStore<node::Node> + Send + Sync> Stream for MerkleKeyVal
let next = self
.merkle
.get_node(leftmost_address.unwrap())
.map_err(|e| api::Error::InternalError(e.into()))?;
.map_err(|e| api::Error::InternalError(Box::new(e)))?;

parents.push((last_node, leftmost_position as u8));

Expand Down Expand Up @@ -1295,12 +1295,12 @@ impl<'a, S: shale::ShaleStore<node::Node> + Send + Sync> Stream for MerkleKeyVal
let root_node = self
.merkle
.get_node(self.merkle_root)
.map_err(|e| api::Error::InternalError(e.into()))?;
.map_err(|e| api::Error::InternalError(Box::new(e)))?;

let (found_node, parents) = self
.merkle
.get_node_and_parents_by_key(root_node, &key)
.map_err(|e| api::Error::InternalError(e.into()))?;
.map_err(|e| api::Error::InternalError(Box::new(e)))?;

let Some(last_node) = found_node else {
return Poll::Ready(None);
Expand Down Expand Up @@ -1338,7 +1338,7 @@ impl<'a, S: shale::ShaleStore<node::Node> + Send + Sync> Stream for MerkleKeyVal
let current_node = self
.merkle
.get_node(child_address)
.map_err(|e| api::Error::InternalError(e.into()))?;
.map_err(|e| api::Error::InternalError(Box::new(e)))?;

let found_key = key_from_parents(&parents);

Expand Down Expand Up @@ -1381,7 +1381,7 @@ impl<'a, S: shale::ShaleStore<node::Node> + Send + Sync> Stream for MerkleKeyVal
.merkle
.get_node(addr)
.map(|node| (node, u8::MAX))
.map_err(|e| api::Error::InternalError(e.into()))?;
.map_err(|e| api::Error::InternalError(Box::new(e)))?;

// stop_descending if:
// - on a branch and it has a value; OR
Expand Down
10 changes: 6 additions & 4 deletions firewood/src/v2/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ pub struct Db<T> {
impl From<DbError> for api::Error {
fn from(value: DbError) -> Self {
match value {
DbError::InvalidParams => api::Error::InternalError(value.into()),
DbError::Merkle(e) => api::Error::InternalError(e.into()),
DbError::InvalidParams => api::Error::InternalError(Box::new(value)),
DbError::Merkle(e) => api::Error::InternalError(Box::new(e)),
DbError::System(e) => api::Error::IO(e.into()),
DbError::KeyNotFound | DbError::CreateError => api::Error::InternalError(value.into()),
DbError::Shale(e) => api::Error::InternalError(e.into()),
DbError::KeyNotFound | DbError::CreateError => {
api::Error::InternalError(Box::new(value))
}
DbError::Shale(e) => api::Error::InternalError(Box::new(e)),
DbError::IO(e) => api::Error::IO(e),
DbError::InvalidProposal => api::Error::InvalidProposal,
}
Expand Down

0 comments on commit a08d9b2

Please sign in to comment.