Skip to content

Commit

Permalink
1499: provide npm output if server starting fails
Browse files Browse the repository at this point in the history
  • Loading branch information
simschla committed Jan 25, 2023
1 parent 7326772 commit 46d370d
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.slf4j.LoggerFactory;

import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.ProcessRunner.LongRunningProcess;
import com.diffplug.spotless.ThrowingEx;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

Expand Down Expand Up @@ -101,13 +103,14 @@ protected boolean needsPrepareNodeServerLayout() {

protected ServerProcessInfo npmRunServer() throws ServerStartException, IOException {
assertNodeServerDirReady();
LongRunningProcess server = null;
try {
// The npm process will output the randomly selected port of the http server process to 'server.port' file
// so in order to be safe, remove such a file if it exists before starting.
final File serverPortFile = new File(this.nodeServerLayout.nodeModulesDir(), "server.port");
NpmResourceHelper.deleteFileIfExists(serverPortFile);
// start the http server in node
Process server = new NpmProcess(this.nodeServerLayout.nodeModulesDir(), this.locations.npmExecutable(), this.locations.nodeExecutable()).start();
server = new NpmProcess(this.nodeServerLayout.nodeModulesDir(), this.locations.npmExecutable(), this.locations.nodeExecutable()).start();

// await the readiness of the http server - wait for at most 60 seconds
try {
Expand All @@ -128,7 +131,7 @@ protected ServerProcessInfo npmRunServer() throws ServerStartException, IOExcept
String serverPort = NpmResourceHelper.readUtf8StringFromFile(serverPortFile).trim();
return new ServerProcessInfo(server, serverPort, serverPortFile);
} catch (IOException | TimeoutException e) {
throw new ServerStartException(e);
throw new ServerStartException("Starting server failed." + (server != null ? "\n\nProcess result:\n" + ThrowingEx.get(server::result) : ""), e);
}
}

Expand Down Expand Up @@ -197,7 +200,7 @@ public void close() throws Exception {
protected static class ServerStartException extends RuntimeException {
private static final long serialVersionUID = -8803977379866483002L;

public ServerStartException(Throwable cause) {
public ServerStartException(String message, Throwable cause) {
super(cause);
}
}
Expand Down

0 comments on commit 46d370d

Please sign in to comment.