Skip to content

Commit 3401d6f

Browse files
committed
Handle block errors
1 parent ebeaac1 commit 3401d6f

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

mithril-common/src/cardano_transaction_parser.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,30 @@ impl CardanoTransactionParser {
119119

120120
let mut blocks = Vec::new();
121121
for block in hardano_blocks {
122-
// TODO block.unwrap ???
123-
// if let Ok() = decode ???
124-
let block = block.unwrap();
125-
if let Ok(multi_era_block) = MultiEraBlock::decode(&block) {
126-
let block = Block::try_convert(multi_era_block, immutable_file.number)
127-
.with_context(|| {
128-
format!(
129-
"CardanoTransactionParser could not read data from block in immutable file: {:?}",
122+
let block = block.map_err(|e| {
123+
anyhow!(e).context(format!(
124+
"Error while reading block in immutable file: '{:?}'",
125+
immutable_file.path
126+
))
127+
})?;
128+
129+
match MultiEraBlock::decode(&block) {
130+
Ok(multi_era_block) => {
131+
let block = Block::try_convert(multi_era_block, immutable_file.number)
132+
.with_context(|| {
133+
format!(
134+
"CardanoTransactionParser could not read data from block in immutable file: {:?}",
135+
immutable_file.path
136+
)
137+
})?;
138+
blocks.push(block);
139+
}
140+
Err(err) => {
141+
return Err(anyhow!(err).context(format!(
142+
"Error while decoding block in immutable file: '{:?}'",
130143
immutable_file.path
131-
)
132-
})?;
133-
blocks.push(block);
144+
)))
145+
}
134146
}
135147
}
136148

0 commit comments

Comments
 (0)