|
1 | 1 | use crate::builtin::HAMT_BIT_WIDTH;
|
2 | 2 | use crate::{ActorError, AsActorError, Hasher};
|
3 |
| -use anyhow::anyhow; |
4 | 3 | use cid::Cid;
|
5 | 4 | use fvm_ipld_blockstore::Blockstore;
|
6 | 5 | use fvm_ipld_hamt as hamt;
|
@@ -153,29 +152,18 @@ where
|
153 | 152 | /// Iterates over all key-value pairs in the map.
|
154 | 153 | pub fn for_each<F>(&self, mut f: F) -> Result<(), ActorError>
|
155 | 154 | where
|
156 |
| - // Note the result type of F uses ActorError. |
157 |
| - // The implementation will extract and propagate any ActorError |
158 |
| - // wrapped in a hamt::Error::Dynamic. |
159 | 155 | F: FnMut(K, &V) -> Result<(), ActorError>,
|
160 | 156 | {
|
161 |
| - self.hamt |
162 |
| - .for_each(|k, v| { |
163 |
| - let key = |
164 |
| - K::from_bytes(k).context_code(ExitCode::USR_ILLEGAL_STATE, "invalid key")?; |
165 |
| - f(key, v).map_err(|e| anyhow!(e)) |
166 |
| - }) |
167 |
| - .map_err(|hamt_err| match hamt_err { |
168 |
| - hamt::Error::Dynamic(e) => match e.downcast::<ActorError>() { |
169 |
| - Ok(ae) => ae, |
170 |
| - Err(e) => ActorError::illegal_state(format!( |
171 |
| - "error in callback traversing HAMT {}: {}", |
172 |
| - self.name, e |
173 |
| - )), |
174 |
| - }, |
175 |
| - e => { |
176 |
| - ActorError::illegal_state(format!("error traversing HAMT {}: {}", self.name, e)) |
177 |
| - } |
178 |
| - }) |
| 157 | + for kv in &self.hamt { |
| 158 | + let (k, v) = kv.with_context_code(ExitCode::USR_ILLEGAL_STATE, || { |
| 159 | + format!("error traversing HAMT {}", self.name) |
| 160 | + })?; |
| 161 | + let k = K::from_bytes(k).with_context_code(ExitCode::USR_ILLEGAL_STATE, || { |
| 162 | + format!("invalid key in HAMT {}", self.name) |
| 163 | + })?; |
| 164 | + f(k, v)?; |
| 165 | + } |
| 166 | + Ok(()) |
179 | 167 | }
|
180 | 168 | }
|
181 | 169 |
|
|
0 commit comments