Skip to content

Commit

Permalink
Merge pull request #585 from tursodatabase/fix-hrana-rusqlite-error-h…
Browse files Browse the repository at this point in the history
…andling

fix hrana handling of rusqlite error
  • Loading branch information
MarinPostma committed Nov 7, 2023
2 parents 0322a55 + 2d19791 commit 94a388d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libsql-server/src/hrana/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ pub fn stmt_error_from_sqld_error(sqld_error: SqldError) -> Result<StmtError, Sq
}
SqldError::Blocked(reason) => 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,
Expand Down
26 changes: 26 additions & 0 deletions libsql-server/tests/standalone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -202,6 +203,31 @@ 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();
}

#[test]
fn random_rowid() {
let mut sim = turmoil::Builder::new().build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: libsql-server/tests/standalone/mod.rs
expression: "conn.execute(\"insert into test values (12)\", ()).await.unwrap_err()"
---
Hrana(
StreamError(
StreamResponseError {
error: Error {
message: "SQLite error: UNIQUE constraint failed: test.x",
},
},
),
)

0 comments on commit 94a388d

Please sign in to comment.