Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Update logging of closed RPC errors #623

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ 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 +171,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 +246,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
4 changes: 4 additions & 0 deletions jsonrpc2/jsonrpc2.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
}
if err != nil {
// sending failed, we will never get a response, so don't leave it pending
if IsRPCClosed(err) {
err = fmt.Errorf("connection to the language server is closed, language server is not running: %w", err)
}
return err

}
// now wait for the response
select {
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)
}
6 changes: 6 additions & 0 deletions jsonrpc2_v2/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ func (c *Connection) Notify(ctx context.Context, method string, params interface
attempted = true
})
if err != nil {
if IsRPCClosed(err) {
err = fmt.Errorf("connection to the language server is closed, language server is not running: %w", err)
}
return err
}

Expand Down Expand Up @@ -351,6 +354,9 @@ func (c *Connection) Call(ctx context.Context, method string, params interface{}

event.Metric(ctx, tag.Started.Of(1))
if err := c.write(ctx, call); err != nil {
if IsRPCClosed(err) {
err = fmt.Errorf("connection to the language server is closed, language server is not running: %w", err)
}
// Sending failed. We will never get a response, so deliver a fake one if it
// wasn't already retired by the connection breaking.
c.updateInFlight(func(s *inFlightState) {
Expand Down
13 changes: 13 additions & 0 deletions jsonrpc2_v2/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)
}
Loading