Skip to content

Commit 40c0a18

Browse files
committed
chore: refine logging error
1 parent 7ee4cc0 commit 40c0a18

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/error.rs

+4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ impl Error {
130130
pub(crate) fn other(message: impl Into<String>, source: impl std::error::Error + Send + Sync + 'static) -> Self {
131131
Self::Other(OtherError { message: Arc::new(message.into()), source: Some(Arc::new(source)) })
132132
}
133+
134+
pub(crate) fn other_from(source: impl std::error::Error + Send + Sync + 'static) -> Self {
135+
Self::Other(OtherError { message: Arc::new(source.to_string()), source: Some(Arc::new(source)) })
136+
}
133137
}
134138

135139
assert_impl_all!(Error: Send, Sync);

src/session/depot.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use super::connection::Connection;
88
use super::request::{MarshalledRequest, OpStat, Operation, SessionOperation, StateResponser};
99
use super::types::WatchMode;
1010
use super::xid::Xid;
11-
use super::SessionId;
1211
use crate::error::Error;
1312
use crate::proto::{OpCode, PredefinedXid, RemoveWatchesRequest};
1413

@@ -205,14 +204,13 @@ impl Depot {
205204
.any(|mode| self.watching_paths.contains_key(&(path, mode)))
206205
}
207206

208-
pub fn write_operations(&mut self, conn: &mut Connection, session_id: SessionId) -> Result<(), Error> {
207+
pub fn write_operations(&mut self, conn: &mut Connection) -> Result<(), Error> {
209208
if !self.has_pending_writes() {
210209
if let Err(err) = conn.flush() {
211210
if err.kind() == io::ErrorKind::WouldBlock {
212211
return Ok(());
213212
}
214-
log::debug!("ZooKeeper session {} write failed {}", session_id, err);
215-
return Err(Error::ConnectionLoss);
213+
return Err(Error::other_from(err));
216214
}
217215
return Ok(());
218216
}
@@ -222,8 +220,7 @@ impl Depot {
222220
if err.kind() == io::ErrorKind::WouldBlock {
223221
return Ok(());
224222
}
225-
log::debug!("ZooKeeper session {} write failed {}", session_id, err);
226-
return Err(Error::ConnectionLoss);
223+
return Err(Error::other_from(err));
227224
},
228225
Ok(written_bytes) => written_bytes,
229226
};

src/session/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,11 @@ impl Session {
369369
fn read_connection(&mut self, conn: &mut Connection, buf: &mut Vec<u8>) -> Result<(), Error> {
370370
match conn.read_buf(buf) {
371371
Ok(0) => {
372-
log::debug!("ZooKeeper session {} encounters server closed", self.session_id);
373372
return Err(Error::ConnectionLoss);
374373
},
375374
Err(err) => {
376375
if err.kind() != io::ErrorKind::WouldBlock {
377-
log::debug!("ZooKeeper session {} encounters read err {}", self.session_id, err);
378-
return Err(Error::ConnectionLoss);
376+
return Err(Error::other_from(err));
379377
}
380378
},
381379
_ => {},
@@ -418,7 +416,7 @@ impl Session {
418416
self.handle_recv_buf(buf, depot)?;
419417
},
420418
_ = conn.writable(), if depot.has_pending_writes() || conn.wants_write() => {
421-
depot.write_operations(conn, self.session_id)?;
419+
depot.write_operations(conn)?;
422420
self.last_send = Instant::now();
423421
},
424422
now = tick.tick() => {
@@ -450,7 +448,7 @@ impl Session {
450448
self.handle_recv_buf(buf, depot)?;
451449
},
452450
_ = conn.writable(), if depot.has_pending_writes() || conn.wants_write() => {
453-
depot.write_operations(conn, self.session_id)?;
451+
depot.write_operations(conn)?;
454452
self.last_send = Instant::now();
455453
},
456454
r = requester.recv(), if !channel_closed => {
@@ -464,7 +462,7 @@ impl Session {
464462
continue;
465463
};
466464
depot.push_session(operation);
467-
depot.write_operations(conn, self.session_id)?;
465+
depot.write_operations(conn)?;
468466
self.last_send = Instant::now();
469467
},
470468
r = unwatch_requester.recv() => if let Some((watcher_id, responser)) = r {
@@ -476,7 +474,7 @@ impl Session {
476474
}
477475
if self.last_ping.is_none() && now >= self.last_send + self.ping_timeout {
478476
self.send_ping(depot, now);
479-
depot.write_operations(conn, self.session_id)?;
477+
depot.write_operations(conn)?;
480478
}
481479
},
482480
}

0 commit comments

Comments
 (0)