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