Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions cmd/wasm-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,15 @@ 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")
}

Expand All @@ -345,27 +347,19 @@ 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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the original reason for adding this panic recovery log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never actually ran into a panic here, but I thought it couldn't hurt to add these logs in the case that we hit that recovery state.

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",
log.Tracef("RPC '%s' succeeded with result: %s",
rpcName, resultJSON)
jsCallback.Invoke(js.ValueOf(resultJSON))
}
Expand Down