@@ -326,11 +326,13 @@ func (w *wasmClient) Status(_ js.Value, _ []js.Value) interface{} {
326
326
327
327
func (w * wasmClient ) InvokeRPC (_ js.Value , args []js.Value ) interface {} {
328
328
if len (args ) != 3 {
329
+ log .Errorf ("Invalid use of wasmClientInvokeRPC, need 3 parameters: rpcName, request, callback" )
329
330
return js .ValueOf ("invalid use of wasmClientInvokeRPC, " +
330
331
"need 3 parameters: rpcName, request, callback" )
331
332
}
332
333
333
334
if w .lndConn == nil {
335
+ log .Errorf ("Attempted to invoke RPC but connection is not ready" )
334
336
return js .ValueOf ("RPC connection not ready" )
335
337
}
336
338
@@ -340,16 +342,28 @@ func (w *wasmClient) InvokeRPC(_ js.Value, args []js.Value) interface{} {
340
342
341
343
method , ok := w .registry [rpcName ]
342
344
if ! ok {
345
+ log .Errorf ("RPC method '%s' not found in registry" , rpcName )
343
346
return js .ValueOf ("rpc with name " + rpcName + " not found" )
344
347
}
345
348
346
349
go func () {
350
+ defer func () {
351
+ if r := recover (); r != nil {
352
+ errMsg := fmt .Sprintf ("Panic in RPC call: %v" , r )
353
+ log .Errorf ("%s\n %s" , errMsg , debug .Stack ())
354
+ jsCallback .Invoke (js .ValueOf (errMsg ))
355
+ }
356
+ }()
357
+
347
358
log .Infof ("Calling '%s' on RPC with request %s" ,
348
359
rpcName , requestJSON )
349
360
cb := func (resultJSON string , err error ) {
350
361
if err != nil {
362
+ log .Errorf ("RPC '%s' failed: %v" , rpcName , err )
351
363
jsCallback .Invoke (js .ValueOf (err .Error ()))
352
364
} else {
365
+ log .Debugf ("RPC '%s' succeeded with result: %s" ,
366
+ rpcName , resultJSON )
353
367
jsCallback .Invoke (js .ValueOf (resultJSON ))
354
368
}
355
369
}
@@ -358,7 +372,6 @@ func (w *wasmClient) InvokeRPC(_ js.Value, args []js.Value) interface{} {
358
372
<- ctx .Done ()
359
373
}()
360
374
return nil
361
-
362
375
}
363
376
364
377
func (w * wasmClient ) GetExpiry (_ js.Value , _ []js.Value ) interface {} {
0 commit comments