@@ -326,11 +326,13 @@ func (w *wasmClient) Status(_ js.Value, _ []js.Value) interface{} {
326326
327327func (w * wasmClient ) InvokeRPC (_ js.Value , args []js.Value ) interface {} {
328328 if len (args ) != 3 {
329+ log .Errorf ("Invalid use of wasmClientInvokeRPC, need 3 parameters: rpcName, request, callback" )
329330 return js .ValueOf ("invalid use of wasmClientInvokeRPC, " +
330331 "need 3 parameters: rpcName, request, callback" )
331332 }
332333
333334 if w .lndConn == nil {
335+ log .Errorf ("Attempted to invoke RPC but connection is not ready" )
334336 return js .ValueOf ("RPC connection not ready" )
335337 }
336338
@@ -340,16 +342,28 @@ func (w *wasmClient) InvokeRPC(_ js.Value, args []js.Value) interface{} {
340342
341343 method , ok := w .registry [rpcName ]
342344 if ! ok {
345+ log .Errorf ("RPC method '%s' not found in registry" , rpcName )
343346 return js .ValueOf ("rpc with name " + rpcName + " not found" )
344347 }
345348
346349 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+
347358 log .Infof ("Calling '%s' on RPC with request %s" ,
348359 rpcName , requestJSON )
349360 cb := func (resultJSON string , err error ) {
350361 if err != nil {
362+ log .Errorf ("RPC '%s' failed: %v" , rpcName , err )
351363 jsCallback .Invoke (js .ValueOf (err .Error ()))
352364 } else {
365+ log .Debugf ("RPC '%s' succeeded with result: %s" ,
366+ rpcName , resultJSON )
353367 jsCallback .Invoke (js .ValueOf (resultJSON ))
354368 }
355369 }
@@ -358,7 +372,6 @@ func (w *wasmClient) InvokeRPC(_ js.Value, args []js.Value) interface{} {
358372 <- ctx .Done ()
359373 }()
360374 return nil
361-
362375}
363376
364377func (w * wasmClient ) GetExpiry (_ js.Value , _ []js.Value ) interface {} {
0 commit comments