From 86e868317696c94a0da764011b59a0bb78aec6a9 Mon Sep 17 00:00:00 2001 From: ad hoc Date: Tue, 7 Nov 2023 18:31:36 +0100 Subject: [PATCH 1/4] fix hrana handling of rusqlite error --- libsql-server/src/hrana/stmt.rs | 3 ++- libsql-server/tests/standalone/mod.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libsql-server/src/hrana/stmt.rs b/libsql-server/src/hrana/stmt.rs index 56569f57ce..b782442f50 100644 --- a/libsql-server/src/hrana/stmt.rs +++ b/libsql-server/src/hrana/stmt.rs @@ -216,7 +216,8 @@ pub fn stmt_error_from_sqld_error(sqld_error: SqldError) -> Result StmtError::Blocked { reason }, SqldError::RpcQueryError(e) => StmtError::Proxy(e.message), - SqldError::RusqliteError(rusqlite_error) => match rusqlite_error { + SqldError::RusqliteError(rusqlite_error) + | SqldError::RusqliteErrorExtended(rusqlite_error, _) => match rusqlite_error { rusqlite::Error::SqliteFailure(sqlite_error, Some(message)) => StmtError::SqliteError { source: sqlite_error, message, diff --git a/libsql-server/tests/standalone/mod.rs b/libsql-server/tests/standalone/mod.rs index e26cf52c44..405b3b00c8 100644 --- a/libsql-server/tests/standalone/mod.rs +++ b/libsql-server/tests/standalone/mod.rs @@ -6,6 +6,7 @@ use super::common; use std::sync::Arc; +use insta::assert_debug_snapshot; use libsql::{Database, Value}; use tempfile::tempdir; use tokio::sync::Notify; @@ -201,3 +202,28 @@ fn execute_transaction() { sim.run().unwrap(); } + +#[test] +fn basic_query_fail() { + let mut sim = turmoil::Builder::new().build(); + + sim.host("primary", make_standalone_server); + + sim.client("test", async { + let db = Database::open_remote_with_connector("http://primary:8080", "", TurmoilConnector)?; + let conn = db.connect()?; + + conn.execute("create table test (x)", ()).await?; + conn.execute("create unique index test_index on test(x)", ()) + .await?; + conn.execute("insert into test values (12)", ()).await?; + assert_debug_snapshot!(conn + .execute("insert into test values (12)", ()) + .await + .unwrap_err()); + + Ok(()) + }); + + sim.run().unwrap(); +} From d433884baa556b3dc7b8b7fa152db10e69620a40 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Tue, 7 Nov 2023 15:38:44 -0500 Subject: [PATCH 2/4] add snapshot --- .../tests__standalone__basic_query_fail.snap.new | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 libsql-server/tests/standalone/snapshots/tests__standalone__basic_query_fail.snap.new diff --git a/libsql-server/tests/standalone/snapshots/tests__standalone__basic_query_fail.snap.new b/libsql-server/tests/standalone/snapshots/tests__standalone__basic_query_fail.snap.new new file mode 100644 index 0000000000..1aa17d2451 --- /dev/null +++ b/libsql-server/tests/standalone/snapshots/tests__standalone__basic_query_fail.snap.new @@ -0,0 +1,14 @@ +--- +source: libsql-server/tests/standalone/mod.rs +assertion_line: 220 +expression: "conn.execute(\"insert into test values (12)\", ()).await.unwrap_err()" +--- +Hrana( + StreamError( + StreamResponseError { + error: Error { + message: "SQLite error: UNIQUE constraint failed: test.x", + }, + }, + ), +) From 513b3cb4c29ad8c626c48e7ec2df19fd314cf2ec Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Tue, 7 Nov 2023 16:00:27 -0500 Subject: [PATCH 3/4] update snapshot --- ...ry_fail.snap.new => tests__standalone__basic_query_fail.snap} | 1 - 1 file changed, 1 deletion(-) rename libsql-server/tests/standalone/snapshots/{tests__standalone__basic_query_fail.snap.new => tests__standalone__basic_query_fail.snap} (94%) diff --git a/libsql-server/tests/standalone/snapshots/tests__standalone__basic_query_fail.snap.new b/libsql-server/tests/standalone/snapshots/tests__standalone__basic_query_fail.snap similarity index 94% rename from libsql-server/tests/standalone/snapshots/tests__standalone__basic_query_fail.snap.new rename to libsql-server/tests/standalone/snapshots/tests__standalone__basic_query_fail.snap index 1aa17d2451..e3667b9c5e 100644 --- a/libsql-server/tests/standalone/snapshots/tests__standalone__basic_query_fail.snap.new +++ b/libsql-server/tests/standalone/snapshots/tests__standalone__basic_query_fail.snap @@ -1,6 +1,5 @@ --- source: libsql-server/tests/standalone/mod.rs -assertion_line: 220 expression: "conn.execute(\"insert into test values (12)\", ()).await.unwrap_err()" --- Hrana( From 2d197918b8e8efc37bd0881565d5f6a5e287bdef Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Tue, 7 Nov 2023 16:35:52 -0500 Subject: [PATCH 4/4] run rustfmt --- libsql-server/tests/standalone/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libsql-server/tests/standalone/mod.rs b/libsql-server/tests/standalone/mod.rs index fd3207454b..4d21662e26 100644 --- a/libsql-server/tests/standalone/mod.rs +++ b/libsql-server/tests/standalone/mod.rs @@ -228,7 +228,6 @@ fn basic_query_fail() { sim.run().unwrap(); } - #[test] fn random_rowid() { let mut sim = turmoil::Builder::new().build(); @@ -249,4 +248,4 @@ fn random_rowid() { }); sim.run().unwrap(); -} \ No newline at end of file +}