It appears that constraint violations (uniqueness, not null, etc) are not reported as errors in Roc for the basic-webserver sqlite impl. Is this a known issue? I know there was some work on a new implementation so maybe this will be fixed by that work anyway.
With this db
create table test (username text unique);
insert into test (username) values ('isaac');
and this server
app [Model, init!, respond!] {
pf: platform "platform/main.roc",
}
import pf.Http exposing [Request, Response]
import pf.Sqlite3
Model : {}
init! : {} => Result Model []
init! = \{} ->
Ok {}
respond! : Request, Model => Result Response _
respond! = \_, _ ->
_ =
Sqlite3.execute! {
path: "bug.db",
query: "insert into test (username) values ('isaac')",
bindings: [],
}
|> try
Ok { status: 200, headers: [], body: [] }
Sqlite.execute! returns an Ok even though the insert failed for violating uniqueness constraint.
We feed straight to the SQlite driver (though one of the more major updates got reverted, so not sure the exact state)
bug is probably ignoring the error case here
https://github.com/roc-lang/basic-webserver/blob/ead72acb6e22c7cc74c2634d4bf83618ea1a924c/crates/roc_host/src/roc.rs#L378
Might be, but I don't think insert returns anything via the cursor. I think with SQlite you have to separately request how many rows were inserted or updated to know if an insert failed.
i think that's fine, the cursor will just return done immediately then. but the statement doesn't execute until you call next it looks like
Ah yeah. Makes sense
Cool, thanks!
Last updated: Jul 05 2025 at 12:14 UTC