Skip to content

Commit e673973

Browse files
authored
Merge pull request #1836 from tursodatabase/lucio/improve-dump-errors
sqld: improve replica dump error handling
2 parents 4a5f373 + 2bf9d48 commit e673973

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

libsql-server/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ pub enum Error {
128128
RuntimeTaskJoinError(#[from] tokio::task::JoinError),
129129
#[error("wal error: {0}")]
130130
LibsqlWal(#[from] libsql_wal::error::Error),
131+
#[error("database is not a primary")]
132+
NotAPrimary,
131133
}
132134

133135
impl AsRef<Self> for Error {
@@ -224,6 +226,7 @@ impl IntoResponse for &Error {
224226
AttachInMigration => self.format_err(StatusCode::BAD_REQUEST),
225227
RuntimeTaskJoinError(_) => self.format_err(StatusCode::INTERNAL_SERVER_ERROR),
226228
LibsqlWal(_) => self.format_err(StatusCode::INTERNAL_SERVER_ERROR),
229+
NotAPrimary => self.format_err(StatusCode::BAD_REQUEST),
227230
}
228231
}
229232
}

libsql-server/src/http/user/dump.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ pub(super) async fn handle_dump(
9898
let conn_maker = state
9999
.namespaces
100100
.with(namespace, |ns| {
101-
assert!(ns.db.is_primary());
102-
ns.db.connection_maker()
101+
if !ns.db.is_primary() {
102+
return Err(Error::NotAPrimary);
103+
}
104+
105+
Ok::<_, crate::Error>(ns.db.connection_maker())
103106
})
104-
.await
105-
.unwrap();
107+
.await??;
106108

107109
let conn = conn_maker.create().await.unwrap();
108110

0 commit comments

Comments
 (0)