Skip to content

Commit dde87b5

Browse files
committed
wasm: detailed rpc logs
1 parent 5267d1d commit dde87b5

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

cmd/wasm-client/main.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,15 @@ func (w *wasmClient) Status(_ js.Value, _ []js.Value) interface{} {
326326

327327
func (w *wasmClient) InvokeRPC(_ js.Value, args []js.Value) interface{} {
328328
if len(args) != 3 {
329+
log.Errorf("Invalid use of wasmClientInvokeRPC, need 3 "+
330+
"parameters: rpcName, request, callback")
329331
return js.ValueOf("invalid use of wasmClientInvokeRPC, " +
330332
"need 3 parameters: rpcName, request, callback")
331333
}
332334

333335
if w.lndConn == nil {
336+
log.Errorf("Attempted to invoke RPC but connection is not "+
337+
"ready")
334338
return js.ValueOf("RPC connection not ready")
335339
}
336340

@@ -340,16 +344,29 @@ func (w *wasmClient) InvokeRPC(_ js.Value, args []js.Value) interface{} {
340344

341345
method, ok := w.registry[rpcName]
342346
if !ok {
347+
log.Errorf("RPC method '%s' not found in registry", rpcName)
343348
return js.ValueOf("rpc with name " + rpcName + " not found")
344349
}
345350

346351
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+
347361
log.Infof("Calling '%s' on RPC with request %s",
348362
rpcName, requestJSON)
349363
cb := func(resultJSON string, err error) {
350364
if err != nil {
365+
log.Errorf("RPC '%s' failed: %v", rpcName, err)
351366
jsCallback.Invoke(js.ValueOf(err.Error()))
352367
} else {
368+
log.Debugf("RPC '%s' succeeded with result: %s",
369+
rpcName, resultJSON)
353370
jsCallback.Invoke(js.ValueOf(resultJSON))
354371
}
355372
}
@@ -358,7 +375,6 @@ func (w *wasmClient) InvokeRPC(_ js.Value, args []js.Value) interface{} {
358375
<-ctx.Done()
359376
}()
360377
return nil
361-
362378
}
363379

364380
func (w *wasmClient) GetExpiry(_ js.Value, _ []js.Value) interface{} {

0 commit comments

Comments
 (0)