Skip to content

Commit

Permalink
feat: Change all error/warn logs to debug
Browse files Browse the repository at this point in the history
  • Loading branch information
oblique committed Jun 10, 2024
1 parent 09cc874 commit 1f5ee85
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/cid_prefix.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cid::{CidGeneric, Version};
use tracing::error;
use tracing::debug;

use crate::multihasher::{MultihasherError, MultihasherTable};

Expand Down Expand Up @@ -89,8 +89,8 @@ impl CidPrefix {
data: &[u8],
) -> Result<CidGeneric<S>, MultihasherError> {
if self.multihash_size > S {
error!(
"Multihash<{}> can not hold multihash of size {}",
debug!(
"beetswap error: Multihash<{}> can not hold multihash of size {}",
S, self.multihash_size
);
return Err(MultihasherError::InvalidMultihashSize);
Expand Down
4 changes: 2 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use libp2p_swarm::{
ConnectionHandlerEvent, ConnectionId, NotifyHandler, StreamProtocol, SubstreamProtocol, ToSwarm,
};
use smallvec::SmallVec;
use tracing::warn;
use tracing::debug;

use crate::incoming_stream::ClientMessage;
use crate::message::Codec;
Expand Down Expand Up @@ -570,7 +570,7 @@ impl<const S: usize> ClientConnectionHandler<S> {
}

fn close_sink_on_error(&mut self, location: &str) {
warn!("sink operation failed, closing: {location}");
debug!("beetswap error: sink operation failed, closing: {location}");
self.sink_state = SinkState::None;
}

Expand Down
23 changes: 16 additions & 7 deletions src/incoming_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cid::CidGeneric;
use fnv::FnvHashMap;
use futures_util::future::{BoxFuture, Fuse, FusedFuture, FutureExt};
use futures_util::stream::StreamExt;
use tracing::error;
use tracing::debug;

use crate::cid_prefix::CidPrefix;
use crate::message::Codec;
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<const S: usize> futures_core::stream::Stream for IncomingStream<S> {
let msg = match self.stream.poll_next_unpin(cx) {
Poll::Ready(Some(Ok(msg))) => msg,
Poll::Ready(Some(Err(e))) => {
error!("Message decoding failed: {e}");
debug!("beetswap error: Message decoding failed: {e}");
return Poll::Ready(None);
}
Poll::Ready(None) => return Poll::Ready(None),
Expand Down Expand Up @@ -116,7 +116,10 @@ async fn process_message<const S: usize>(
let cid = match CidGeneric::try_from(&block_presence.cid[..]) {
Ok(cid) => cid,
Err(e) => {
error!("Invalid CID bytes: {}: {:?}", e, block_presence.cid);
debug!(
"beetswap error: Invalid CID bytes: {}: {:?}",
e, block_presence.cid
);
return None;
}
};
Expand All @@ -130,23 +133,29 @@ async fn process_message<const S: usize>(

for payload in msg.payload {
let Some(cid_prefix) = CidPrefix::from_bytes(&payload.prefix) else {
error!("block.prefix not decodable: {:?}", payload.prefix);
debug!(
"beeswap error: block.prefix not decodable: {:?}",
payload.prefix
);
return None;
};

let cid = match cid_prefix.to_cid(&multihasher, &payload.data).await {
Ok(cid) => cid,
Err(MultihasherError::UnknownMultihashCode) => {
error!("Unknown multihash code: {}", cid_prefix.multihash_code());
debug!(
"beetswap error: Multihasher non-fatal error: Unknown multihash code: {}",
cid_prefix.multihash_code()
);
continue;
}
Err(MultihasherError::Custom(e)) => {
error!("{e}");
debug!("beetswap error: Multihasher non-fatal error: {e}");
continue;
}
// Any other error is fatal and we need to close the stream.
Err(e) => {
error!("{e}");
debug!("beetswap error: Multihasher fatal error: {e}");
return None;
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use libp2p_swarm::{
ConnectionHandlerEvent, NotifyHandler, StreamProtocol, SubstreamProtocol, ToSwarm,
};
use smallvec::SmallVec;
use tracing::{debug, trace, warn};
use tracing::{debug, trace};

use crate::incoming_stream::ServerMessage;
use crate::message::Codec;
Expand Down Expand Up @@ -271,7 +271,7 @@ where
self.outgoing_queue.push_back((cid, data));
}
Err(e) => {
warn!("Fetching {cid} from blockstore failed: {e}");
debug!("beetswap error: Fetching {cid} from blockstore failed: {e}");
}
}
}
Expand Down Expand Up @@ -393,7 +393,7 @@ impl<const S: usize> ServerConnectionHandler<S> {
}

fn close_sink_on_error(&mut self, location: &str) {
warn!("sink operation failed, closing: {location}");
debug!("beetswap error: sink operation failed, closing: {location}");
self.sink = SinkState::None;
}

Expand Down

0 comments on commit 1f5ee85

Please sign in to comment.