Skip to content

Commit

Permalink
fix: Log & continue on mapper errors (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Jan 13, 2022
1 parent e47e021 commit e9b88b9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/mapper/cip25.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ impl EventWriter {
}

pub(crate) fn crawl_metadata_label_721(&self, content: &Metadatum) -> Result<(), Error> {
let version = self
.search_cip25_version(content)
.unwrap_or_else(|| "1.0".to_string());

let entries = match content {
Metadatum::Map(map) => map,
_ => return Err("expected 721 content to be a map".into()),
};

let version = self
.search_cip25_version(content)
.unwrap_or_else(|| "1.0".to_string());

for (key, sub_content) in entries.iter() {
if let Some(policy) = is_policy_key(key) {
self.crawl_721_policy(&version, &policy, sub_content)?;
Expand Down
5 changes: 4 additions & 1 deletion src/sources/n2c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use pallas::{
use crate::{
framework::{Error, EventData},
mapper::EventWriter,
utils::SwallowResult,
};

#[derive(Debug)]
Expand Down Expand Up @@ -64,7 +65,9 @@ impl Observer<Content> for ChainObserver {
let Self(writer) = self;
let Content(block) = content;

writer.crawl(block)?;
writer
.crawl(block)
.ok_or_warn("error crawling block for events");

Ok(())
}
Expand Down
6 changes: 5 additions & 1 deletion src/sources/n2n/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::sync::mpsc::{Receiver, SyncSender};
use crate::{
framework::{Error, EventData},
mapper::EventWriter,
utils::SwallowResult,
};

#[derive(Debug)]
Expand Down Expand Up @@ -67,7 +68,10 @@ impl BlockObserver for Block2EventMapper {
match maybe_block {
Ok(alonzo::BlockWrapper(_, block)) => {
let Self(writer) = self;
writer.crawl(&block)?;

writer
.crawl(&block)
.ok_or_warn("error crawling block for events");
}
Err(err) => {
log::error!("{:?}", err);
Expand Down
15 changes: 15 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
use crate::framework::Error;

pub mod throttle;

pub(crate) trait SwallowResult {
fn ok_or_warn(self, context: &'static str);
}

impl SwallowResult for Result<(), Error> {
fn ok_or_warn(self, context: &'static str) {
match self {
Ok(_) => (),
Err(e) => log::warn!("{}: {:?}", context, e),
}
}
}

0 comments on commit e9b88b9

Please sign in to comment.