Skip to content

Commit 69b315e

Browse files
ctruedenclaude
andcommitted
lsp: quiet expected failures in logs and tests
A language server that cannot start (typically, one not installed) is now warned of in one line, with the stack trace only at debug level, since the warning recurs with each retry. The tests that fail on purpose no longer print warnings and stack traces to the build output: failing launchers log to a recording log (whose warning testRetry now checks), script processing tests log only errors, and a destroyed fake server drops its writes, as a dead process would, rather than lsp4j complaining of its closed pipe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 13c80fe commit 69b315e

5 files changed

Lines changed: 60 additions & 4 deletions

File tree

‎scijava-lsp/src/main/java/org/scijava/lsp/server/ServerProcesses.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,11 @@ private void start() {
288288
// Could not start (e.g. the process failed, or did not
289289
// initialize in time): say so (it waits before trying again).
290290
s.completeExceptionally(t);
291+
// NB: Typically the server is simply not installed, and this
292+
// recurs with each retry, so the details are only for debugging.
291293
log.warn("Could not start " + launcher.language() +
292-
" language server for " + env, t);
294+
" language server for " + env + ": " + t);
295+
log.debug(t);
293296
}
294297
else {
295298
// NB: Interrupted by a shutdown, which failed it already:

‎scijava-lsp/src/test/java/org/scijava/lsp/ScriptProcessingTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public class ScriptProcessingTest {
6161
@BeforeEach
6262
public void setUp() {
6363
context = new Context();
64+
// NB: The tests' unusual scripts are warned of, as expected; quiet that.
65+
context.service(LogService.class).setLevel(LogLevel.ERROR);
6466
processing = new ScriptProcessing(() -> context);
6567
}
6668

‎scijava-lsp/src/test/java/org/scijava/lsp/server/FakeServers.java‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
package org.scijava.lsp.server;
3131

32+
import java.io.FilterOutputStream;
3233
import java.io.IOException;
3334
import java.io.InputStream;
3435
import java.io.OutputStream;
@@ -65,6 +66,9 @@
6566
import org.eclipse.lsp4j.services.LanguageServer;
6667
import org.eclipse.lsp4j.services.TextDocumentService;
6768
import org.eclipse.lsp4j.services.WorkspaceService;
69+
import org.scijava.log.AbstractLogService;
70+
import org.scijava.log.LogLevel;
71+
import org.scijava.log.LogMessage;
6872
import org.scijava.lsp.Environment;
6973

7074
/**
@@ -111,6 +115,24 @@ static void waitFor(final java.util.function.BooleanSupplier c)
111115
}
112116
}
113117

118+
/** A log that keeps its messages, rather than printing them. */
119+
static final class RecordingLog extends AbstractLogService {
120+
121+
/** The messages logged, in order. */
122+
final List<LogMessage> messages = new CopyOnWriteArrayList<>();
123+
124+
@Override
125+
protected void messageLogged(final LogMessage message) {
126+
messages.add(message);
127+
}
128+
129+
/** Whether a warning containing the given text was logged. */
130+
boolean warned(final String text) {
131+
return messages.stream().anyMatch(m -> m.level() == LogLevel.WARN && m
132+
.text().contains(text));
133+
}
134+
}
135+
114136
/** Starts fake servers, connected by pipes. */
115137
static class Launcher implements ServerLauncher {
116138

@@ -129,8 +151,34 @@ public Process start(final Environment env) throws IOException {
129151
final PipedInputStream serverIn = new PipedInputStream(1 << 16);
130152
final PipedOutputStream clientOut = new PipedOutputStream(serverIn);
131153
final Server server = newServer();
154+
// NB: Once destroyed, a process writes nothing more; so too a fake
155+
// server, rather than failing (loudly) to write to its closed pipe.
156+
final OutputStream serverOutput = new FilterOutputStream(serverOut) {
157+
158+
@Override
159+
public void write(final int b) throws IOException {
160+
try {
161+
out.write(b);
162+
}
163+
catch (final IOException exc) {
164+
if (server.alive) throw exc;
165+
}
166+
}
167+
168+
@Override
169+
public void write(final byte[] b, final int off, final int len)
170+
throws IOException
171+
{
172+
try {
173+
out.write(b, off, len);
174+
}
175+
catch (final IOException exc) {
176+
if (server.alive) throw exc;
177+
}
178+
}
179+
};
132180
final org.eclipse.lsp4j.jsonrpc.Launcher<org.eclipse.lsp4j.services.LanguageClient> launcher =
133-
LSPLauncher.createServerLauncher(server, serverIn, serverOut);
181+
LSPLauncher.createServerLauncher(server, serverIn, serverOutput);
134182
server.client = launcher.getRemoteProxy();
135183
launcher.startListening();
136184
started.add(server);

‎scijava-lsp/src/test/java/org/scijava/lsp/server/ProcessLanguageServerTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public void testFallbackCapabilities() throws Exception {
194194
public Process start(final Environment env) throws IOException {
195195
throw new IOException("No such server");
196196
}
197-
}, new StderrLogService(), 60_000, 2, System::currentTimeMillis);
197+
}, new FakeServers.RecordingLog(), 60_000, 2, System::currentTimeMillis);
198198
try {
199199
final ProcessLanguageServer s = (ProcessLanguageServer) failing.server(
200200
ENV);

‎scijava-lsp/src/test/java/org/scijava/lsp/server/ServerProcessesTest.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public void testStaleSlotReplaced() throws Exception {
153153
public void testRetry() throws Exception {
154154
// Create a ServerProcesses whose starts always fail, counting the tries
155155
final AtomicLong tries = new AtomicLong();
156+
final FakeServers.RecordingLog log = new FakeServers.RecordingLog();
156157
final ServerProcesses failing = new ServerProcesses(
157158
new FakeServers.Launcher()
158159
{
@@ -162,14 +163,16 @@ public Process start(final Environment env) throws IOException {
162163
tries.incrementAndGet();
163164
throw new IOException("No such server");
164165
}
165-
}, new StderrLogService(), 60_000, 2, now::get);
166+
}, log, 60_000, 2, now::get);
166167
try {
167168
// Ask for a ServerProcess, get a failure
168169
final ServerProcesses.Slot slot = failing.slot(ENV);
169170
final CompletableFuture<ServerProcess> failed = slot.process();
170171
assertThrows(ExecutionException.class, () -> failed.get(10,
171172
TimeUnit.SECONDS));
172173
assertEquals(1, tries.get());
174+
// ...and a warning of it.
175+
waitFor(() -> log.warned("No such server"));
173176

174177
// Ask again, get another failure...
175178
assertSame(failed, slot.process());

0 commit comments

Comments
 (0)