Skip to content

Commit

Permalink
update logging of closed RPC errors
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Brugarolas <abrugaro@redhat.com>
  • Loading branch information
abrugaro committed Jun 20, 2024
1 parent b5c166d commit b56144b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ func (p *javaServiceClient) GetAllSymbols(ctx context.Context, query, location s

var refs []protocol.WorkspaceSymbol
err := p.rpc.Call(ctx, "workspace/executeCommand", wsp, &refs)
if err != nil {
p.log.Error(err, "unable to ask for tackle rule entry")
if jsonrpc2.IsRPCClosed(err) {
p.log.Error(err, "connection to the language server is closed, language server is not running")
} else {
p.log.Error(err, "unable to ask for Konveyor rule entry")
}

return refs
Expand Down Expand Up @@ -167,7 +169,11 @@ func (p *javaServiceClient) GetAllReferences(ctx context.Context, symbol protoco
res := []protocol.Location{}
err := p.rpc.Call(ctx, "textDocument/references", params, &res)
if err != nil {
fmt.Printf("Error rpc: %v", err)
if jsonrpc2.IsRPCClosed(err) {
p.log.Error(err, "connection to the language server is closed, language server is not running")
} else {
fmt.Printf("Error rpc: %v", err)
}
}
return res
}
Expand Down Expand Up @@ -238,7 +244,11 @@ func (p *javaServiceClient) initialization(ctx context.Context) {
var result protocol.InitializeResult
for i := 0; i < 10; i++ {
if err := p.rpc.Call(ctx, "initialize", params, &result); err != nil {
p.log.Error(err, "initialize failed")
if jsonrpc2.IsRPCClosed(err) {
p.log.Error(err, "connection to the language server is closed, language server is not running")
} else {
p.log.Error(err, "initialize failed")
}
continue
}
break
Expand Down
13 changes: 13 additions & 0 deletions jsonrpc2/rpcerr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package jsonrpc2

import (
"strings"
)

var errFileClosed = "file already closed"
var errBrokenPipe = "broken pipe"

func IsRPCClosed(err error) bool {
var errMsg = err.Error()
return strings.HasSuffix(errMsg, errFileClosed) || strings.HasSuffix(errMsg, errBrokenPipe)
}

0 comments on commit b56144b

Please sign in to comment.