From 019c2ce442466523409ecef5f00495fe67dae313 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Thu, 5 Dec 2024 17:51:37 -0500 Subject: [PATCH] libsql: Clean up error handling in try_pull Returns an error when one of the pull_one_frame calls fail. It will continue to write the metadata and end the insert before returning the error to the user. This also removes the println for a call to tracing. --- libsql/src/local/database.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libsql/src/local/database.rs b/libsql/src/local/database.rs index c69045728b..8f836daef3 100644 --- a/libsql/src/local/database.rs +++ b/libsql/src/local/database.rs @@ -471,6 +471,9 @@ impl Database { let mut frame_no = sync_ctx.durable_frame_num() + 1; let conn = self.connect()?; conn.wal_insert_begin()?; + + let mut err = None; + loop { match sync_ctx.pull_one_frame(generation, frame_no).await { Ok(frame) => { @@ -478,18 +481,23 @@ impl Database { frame_no += 1; } Err(e) => { - println!("pull_one_frame error: {:?}", e); + tracing::debug!("pull_one_frame error: {:?}", e); + err.replace(e); break; } } - } conn.wal_insert_end()?; sync_ctx.write_metadata().await?; - Ok(crate::database::Replicated { - frame_no: None, - frames_synced: 1, - }) + + if let Some(err) = err { + Err(err) + } else { + Ok(crate::database::Replicated { + frame_no: None, + frames_synced: 1, + }) + } } pub(crate) fn path(&self) -> &str {