Skip to content

Commit 6400a44

Browse files
Gabriela Araujo BrittoGabriela Araujo Britto
authored andcommitted
log error in notification handling
1 parent 5b97596 commit 6400a44

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

internal/lsp/server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,10 @@ func (s *Server) sendResult(id *jsonrpc.ID, result any) error {
509509
}
510510

511511
func (s *Server) sendError(id *jsonrpc.ID, err error) error {
512-
// Do not send errors for notifications,
512+
// Do not send error response for notifications,
513513
// except for parse errors which may occur before determining if the message is a request or notification.
514514
if id == nil && !errors.Is(err, lsproto.ErrorCodeInvalidRequest) {
515+
s.logger.Errorf("error handling notification: %s", err)
515516
return nil
516517
}
517518
code := lsproto.ErrorCodeInternalError

internal/lsp/server_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77
"io"
8+
"strings"
89
"sync"
910
"testing"
1011

@@ -180,11 +181,12 @@ func TestServerInvalidNotificationParams(t *testing.T) {
180181

181182
reader := ToReader(io.NopCloser(bytes.NewReader([]byte(rawMessage))))
182183
writer := &collectingWriter{}
184+
stderr := &strings.Builder{}
183185

184186
server := NewServer(&ServerOptions{
185187
In: reader,
186188
Out: writer,
187-
Err: io.Discard,
189+
Err: stderr,
188190
Cwd: "/test",
189191
})
190192

@@ -208,4 +210,7 @@ func TestServerInvalidNotificationParams(t *testing.T) {
208210
}
209211
}
210212
assert.Assert(t, !foundError, "expected no error response for invalid notification")
213+
errstr := stderr.String()
214+
assert.Assert(t, strings.Contains(errstr, "error handling notification"),
215+
"expected error log to contain 'error handling notification', got %q", errstr)
211216
}

0 commit comments

Comments
 (0)