diff --git a/cmd/wasm-client/main.go b/cmd/wasm-client/main.go index 3317791..f2b1fe6 100644 --- a/cmd/wasm-client/main.go +++ b/cmd/wasm-client/main.go @@ -326,11 +326,15 @@ func (w *wasmClient) Status(_ js.Value, _ []js.Value) interface{} { func (w *wasmClient) InvokeRPC(_ js.Value, args []js.Value) interface{} { if len(args) != 3 { + log.Errorf("Invalid use of wasmClientInvokeRPC, need 3 "+ + "parameters: rpcName, request, callback") return js.ValueOf("invalid use of wasmClientInvokeRPC, " + "need 3 parameters: rpcName, request, callback") } if w.lndConn == nil { + log.Errorf("Attempted to invoke RPC but connection is not "+ + "ready") return js.ValueOf("RPC connection not ready") } @@ -340,16 +344,29 @@ func (w *wasmClient) InvokeRPC(_ js.Value, args []js.Value) interface{} { method, ok := w.registry[rpcName] if !ok { + log.Errorf("RPC method '%s' not found in registry", rpcName) return js.ValueOf("rpc with name " + rpcName + " not found") } go func() { + defer func() { + if r := recover(); r != nil { + errMsg := fmt.Sprintf("Panic in RPC call: "+ + "%v", r) + log.Errorf("%s\n%s", errMsg, debug.Stack()) + jsCallback.Invoke(js.ValueOf(errMsg)) + } + }() + log.Infof("Calling '%s' on RPC with request %s", rpcName, requestJSON) cb := func(resultJSON string, err error) { if err != nil { + log.Errorf("RPC '%s' failed: %v", rpcName, err) jsCallback.Invoke(js.ValueOf(err.Error())) } else { + log.Debugf("RPC '%s' succeeded with result: %s", + rpcName, resultJSON) jsCallback.Invoke(js.ValueOf(resultJSON)) } } @@ -358,7 +375,6 @@ func (w *wasmClient) InvokeRPC(_ js.Value, args []js.Value) interface{} { <-ctx.Done() }() return nil - } func (w *wasmClient) GetExpiry(_ js.Value, _ []js.Value) interface{} {