[TS] log when an exception is thrown inside of a trait call
[ldk-java] / typescript_strings.py
index b387fd4ddb3040d12ebf51a6cad6898290413c87..89aa57a22b2d3f29bd68bbf45809f3ec2d5a3afe 100644 (file)
@@ -361,6 +361,7 @@ export async function initializeWasmFromBinary(bin: Uint8Array) {
        await initializeWasmFromUint8Array(bin);
 }
 
+export * from './structs/UtilMethods.mjs';
 """)
 
         self.bindings_version_file = """export function get_ldk_java_bindings_version(): String {
@@ -1630,14 +1631,21 @@ js_invoke = function(obj_ptr: number, fn_id: number, arg1: bigint|number, arg2:
                 bindings.write(f"\t\tcase {str(f)}: fn = Object.getOwnPropertyDescriptor(obj, \"{self.function_ptrs[f][1]}\"); break;\n")
 
             bindings.write("""\t\tdefault:
-                       console.error("Got unknown function call from C!");
-                       throw new Error("Got unknown function call from C!");
+                       console.error("Got unknown function call with id " + fn_id + " from C!");
+                       throw new Error("Got unknown function call with id " + fn_id + " from C!");
        }
        if (fn == null || fn == undefined) {
-               console.error("Got function call on incorrect JS object!");
-               throw new Error("Got function call on incorrect JS object!");
+               console.error("Got function call with id " + fn_id + " on incorrect JS object: " + obj);
+               throw new Error("Got function call with id " + fn_id + " on incorrect JS object: " + obj);
+       }
+       var ret;
+       try {
+               ret = fn.value.bind(obj)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
+       } catch (e) {
+               console.error("Got an exception calling function with id " + fn_id + "! This is fatal.");
+               console.error(e);
+               throw e;
        }
-       const ret = fn.value.bind(obj)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
        if (ret === undefined || ret === null) return BigInt(0);
        return BigInt(ret);
 }""")