Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions integration-tests/sqlite/src/Main.gren
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,22 @@ tests fsPerm =
, awaitError "syntax error" (Sqlite.executeScript db "SELECT *") <| \err ->
test "Is right type" <| \_ ->
when err is
Sqlite.GenericError _ ->
Sqlite.Error _ ->
Expect.pass

_ ->
Expect.fail "Unexpected error type"
, awaitError "Define friends" (defineFriendsById 1 2 db) <| \err ->
test "Fails due to foreign key constraints" <| \_ ->
when err is
Sqlite.ForeignKeyError message ->
if String.contains "foreign key" (String.toLower message) then
Expect.pass

else
Expect.fail "Correct error type, but message doesn't mention foreign key"
Sqlite.ConstraintError Sqlite.ForeignKeyConstraintError ->
Expect.pass

_ ->
Expect.fail "Failed for unknown reason"
, awaitError "Too many templates" (execBadTemplate 3 db) <| \err ->
test "Is invalid" <| \_ ->
Expect.equal (Sqlite.GenericError "Unknown named parameter 'id1'") err
Expect.equal (Sqlite.Error "Unknown named parameter 'id1'") err
, await "Closing the database" (Sqlite.close db) <| \_ ->
test "Works" <| \_ ->
Expect.pass
Expand Down Expand Up @@ -203,11 +199,11 @@ tests fsPerm =
, awaitError "Define same friends again" (defineFriends robin.name justin.name db) <| \err ->
test "Fails due to unique constraint" <| \_ ->
when err is
Sqlite.UniqueConstraintError _ ->
Sqlite.ConstraintError Sqlite.UniqueConstraintError ->
Expect.pass

_ ->
Expect.fail ("Expected UniqueConstraintError, but got: " ++ Sqlite.errorToString err)
Expect.fail ("Expected UniqueConstraintError")
]
]
, await "Open db for executeAll tests" createTestDb <| \db ->
Expand Down
14 changes: 4 additions & 10 deletions src/Gren/Kernel/Sqlite.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*

import Sqlite exposing (GenericError, ForeignKeyError, UniqueConstraintError, DecodingError, MultipleResultsError)
import Sqlite exposing (errorCodeToError, DecodingError, MultipleResultsError)
import Gren.Kernel.FilePath exposing (toString)
import Gren.Kernel.Scheduler exposing (binding, succeed, fail)
import Gren.Kernel.Json exposing (wrap, unwrap)
Expand Down Expand Up @@ -255,13 +255,7 @@ var _Sqlite_executeScript = F2(function (script, db) {
});

var _Sqlite_constructError = function (e) {
if (e.errcode === 787) {
return __Scheduler_fail(__Sqlite_ForeignKeyError(e.message));
}

if (e.errcode === 2067) {
return __Scheduler_fail(__Sqlite_UniqueConstraintError(e.message));
}

return __Scheduler_fail(__Sqlite_GenericError(e.message));
return __Scheduler_fail(
A3(__Sqlite_errorCodeToError, e.code, e.errcode, e.message),
Comment thread
joeybright marked this conversation as resolved.
);
};
Loading
Loading