Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Log & continue on mapper errors #53

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
}
}
}