quickjs-tart

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

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

more logging for sqlite3

Diffstat:
Mqtart.c | 24++++++++++++++++++++++++
Mtart_module.c | 5+++++
2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/qtart.c b/qtart.c @@ -305,6 +305,23 @@ handle_host_message(void *cls, const char *msg) printf("message from JS to host: %s\n", msg); } +static JSValue js_native_log(JSContext *ctx, + JSValueConst this_obj, + int argc, JSValueConst *argv) +{ + const char *tag = NULL; + const char *msg = NULL; + uint32_t level = 0; + + JS_ToUint32(ctx, &level, argv[0]); + tag = JS_ToCString(ctx, argv[1]); + msg = JS_ToCString(ctx, argv[2]); + printf("log: %u, %s, %s\n", (unsigned int) level, tag, msg); + JS_FreeCString(ctx, tag); + JS_FreeCString(ctx, msg); + return JS_UNDEFINED; +} + int main(int argc, char **argv) { JSRuntime *rt; @@ -455,8 +472,15 @@ int main(int argc, char **argv) NULL); if (!empty_run) { + JSValue global_obj; + js_std_add_helpers(ctx, argc - optind, argv + optind); + global_obj = JS_GetGlobalObject(ctx); + JS_SetPropertyStr(ctx, global_obj, "__nativeLog", + JS_NewCFunction(ctx, js_native_log, "__nativeLog", 3)); + JS_FreeValue(ctx, global_obj); + /* make 'std', 'os' and 'tart' visible to non module code */ if (load_std) { const char *str = "import * as std from 'std';\n" diff --git a/tart_module.c b/tart_module.c @@ -1598,6 +1598,7 @@ static JSValue js_sqlite3_open(JSContext *ctx, JSValue this_val, goto done; } + fprintf(stderr, "opening sqlite3 db at %s", filename), ret = sqlite3_open_v2(filename, &sqlite3_db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); if (SQLITE_OK != ret) { if (NULL == sqlite3_db) { @@ -1605,7 +1606,11 @@ static JSValue js_sqlite3_open(JSContext *ctx, JSValue this_val, ret_val = JS_ThrowInternalError(ctx, "unable to open database (OOM)"); } else { // get error details from DB before we close it + fprintf(stderr, "sqlite3_open failed: %s / %s\n", + sqlite3_errstr(ret), + sqlite3_errmsg(sqlite3_db)); ret_val = throw_sqlite3_error(ctx, sqlite3_db); + fprintf(stderr, "calling sqlite3 close on failed db\n"); (void)sqlite3_close_v2(sqlite3_db); } goto done;