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

improve logical error logging #47987

Merged
merged 1 commit into from
May 13, 2024
Merged
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
60 changes: 28 additions & 32 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,20 @@ enum Error {
}

impl Error {
// returns true if the error represents a logic error (a bug in the code)
// that could warrant a panic or high severity log level
fn is_logical(&self) -> bool {
matches!(self, Error::ValueActive)
}

fn log_level(&self) -> Level {
if self.is_logical() {
Level::Error
} else {
Level::Debug
}
}

fn to_condition(&self) -> &'static str {
match self {
Error::Io(e) if e.kind() == io::ErrorKind::ConnectionRefused => {
Expand Down Expand Up @@ -2371,14 +2385,7 @@ pub async fn server_req_connection<P: CidProvider, S: AsyncRead + AsyncWrite + I
.await
{
Ok(()) => debug!("server-conn {}: finished", cid),
Err(e) => {
let level = match e {
Error::ValueActive => Level::Error,
_ => Level::Debug,
};

log!(level, "server-conn {}: process error: {:?}", cid, e);
}
Err(e) => log!(e.log_level(), "server-conn {}: process error: {:?}", cid, e),
}
}

Expand Down Expand Up @@ -4452,14 +4459,7 @@ pub async fn server_stream_connection<P: CidProvider, S: AsyncRead + AsyncWrite
.await
{
Ok(()) => debug!("server-conn {}: finished", cid),
Err(e) => {
let level = match e {
Error::ValueActive => Level::Error,
_ => Level::Debug,
};

log!(level, "server-conn {}: process error: {:?}", cid, e);
}
Err(e) => log!(e.log_level(), "server-conn {}: process error: {:?}", cid, e),
}
}

Expand Down Expand Up @@ -5194,14 +5194,12 @@ pub async fn client_req_connection(
.await
{
Ok(()) => debug!("client-conn {}: finished", log_id),
Err(e) => {
let level = match e {
Error::ValueActive => Level::Error,
_ => Level::Debug,
};

log!(level, "client-conn {}: process error: {:?}", log_id, e);
}
Err(e) => log!(
e.log_level(),
"client-conn {}: process error: {:?}",
log_id,
e
),
}
}

Expand Down Expand Up @@ -6185,14 +6183,12 @@ pub async fn client_stream_connection<E>(
.await
{
Ok(()) => debug!("client-conn {}: finished", log_id),
Err(e) => {
let level = match e {
Error::ValueActive => Level::Error,
_ => Level::Debug,
};

log!(level, "client-conn {}: process error: {:?}", log_id, e);
}
Err(e) => log!(
e.log_level(),
"client-conn {}: process error: {:?}",
log_id,
e
),
}
}

Expand Down
Loading