quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

commit 248834b1b48905ff29d52d6f14ff5abda175a4d9
parent 5aad1c733a8e1e661e9a650ad87e50c60d4f48ce
Author: Florian Dold <florian@dold.me>
Date:   Fri, 12 Jan 2024 13:13:40 +0100

report details in exception when sqlite3 open fails

Diffstat:
Mtart_module.c | 14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tart_module.c b/tart_module.c @@ -1600,8 +1600,14 @@ static JSValue js_sqlite3_open(JSContext *ctx, JSValue this_val, ret = sqlite3_open_v2(filename, &sqlite3_db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); if (SQLITE_OK != ret) { - (void)sqlite3_close_v2(sqlite3_db); - ret_val = JS_ThrowTypeError(ctx, "unable to open database"); + if (NULL == sqlite3_db) { + // sqlite3 was unable to even allocate memory + ret_val = JS_ThrowInternalError(ctx, "unable to open database (OOM)"); + } else { + // get error details from DB before we close it + ret_val = throw_sqlite3_error(ctx, sqlite3_db); + (void)sqlite3_close_v2(sqlite3_db); + } goto done; } db_obj = JS_NewObjectClass(ctx, js_sqlite3_database_class_id); @@ -1662,7 +1668,7 @@ static JSValue js_sqlite3_prepare(JSContext *ctx, JSValue this_val, ret_val = JS_ThrowTypeError(ctx, "unable to prepare"); goto done; } - + stmt_obj = JS_NewObjectClass(ctx, js_sqlite3_statement_class_id); JS_SetOpaque(stmt_obj, stmt); ret_val = stmt_obj; @@ -1698,7 +1704,7 @@ static JSValue js_sqlite3_exec(JSContext *ctx, JSValue this_val, sqlite3 *sqlite3_db; JSValue db_handle = argv[0]; JSValue stmt_str = argv[1]; - const char *stmt_cstr; + const char *stmt_cstr = NULL; int res; char *errmsg = NULL; JSValue ret_val = JS_UNDEFINED;