|
34 | 34 | import java.util.UUID; |
35 | 35 | import java.util.concurrent.CompletableFuture; |
36 | 36 | import java.util.concurrent.CompletionException; |
37 | | -import java.util.concurrent.atomic.AtomicBoolean; |
38 | 37 | import java.util.concurrent.atomic.AtomicReference; |
39 | 38 | import java.util.function.BiConsumer; |
40 | 39 | import java.util.regex.Pattern; |
@@ -107,7 +106,7 @@ public abstract class AbstractDevServerRunner implements DevModeHandler { |
107 | 106 | private final boolean reuseDevServer; |
108 | 107 | private final File devServerPortFile; |
109 | 108 |
|
110 | | - private AtomicBoolean isDevServerFailedToStart = new AtomicBoolean(); |
| 109 | + private AtomicReference<String> devServerFailure = new AtomicReference<>(); |
111 | 110 |
|
112 | 111 | private final CompletableFuture<Void> devServerStartFuture; |
113 | 112 |
|
@@ -217,8 +216,11 @@ void doStartDevModeServer() throws ExecutionFailedException { |
217 | 216 | Process process = doStartDevServer(); |
218 | 217 | devServerProcess.set(process); |
219 | 218 | if (!isRunning()) { |
220 | | - throw new IllegalStateException("Startup of " + getServerName() |
221 | | - + " failed. Output was:\n" + getFailedOutput()); |
| 219 | + IllegalStateException exception = new IllegalStateException( |
| 220 | + "Startup of " + getServerName() |
| 221 | + + " failed. Output was:\n" + getFailedOutput()); |
| 222 | + getLogger().error("Dev server failed to start", exception); |
| 223 | + throw exception; |
222 | 224 | } |
223 | 225 |
|
224 | 226 | long ms = (System.nanoTime() - start) / 1000000; |
@@ -648,22 +650,30 @@ public HttpURLConnection prepareConnection(String path, String method) |
648 | 650 | public boolean handleRequest(VaadinSession session, VaadinRequest request, |
649 | 651 | VaadinResponse response) throws IOException { |
650 | 652 | return handleRequestInternal(session, request, response, |
651 | | - devServerStartFuture, isDevServerFailedToStart); |
| 653 | + devServerStartFuture, devServerFailure); |
652 | 654 | } |
653 | 655 |
|
654 | 656 | static boolean handleRequestInternal(VaadinSession session, |
655 | 657 | VaadinRequest request, VaadinResponse response, |
656 | 658 | CompletableFuture<?> devServerStartFuture, |
657 | | - AtomicBoolean isDevServerFailedToStart) throws IOException { |
658 | | - if (devServerStartFuture.isDone()) { |
659 | | - // The server has started, check for any exceptions in the startup |
660 | | - // process |
| 659 | + AtomicReference<String> devServerFailure) throws IOException { |
| 660 | + if (devServerFailure.get() == null && devServerStartFuture.isDone()) { |
661 | 661 | try { |
662 | 662 | devServerStartFuture.getNow(null); |
663 | 663 | } catch (CompletionException exception) { |
664 | | - isDevServerFailedToStart.set(true); |
665 | | - throw getCause(exception); |
| 664 | + RuntimeException cause = getCause(exception); |
| 665 | + devServerFailure.set("The Vite dev server failed to start: " |
| 666 | + + cause.getMessage()); |
666 | 667 | } |
| 668 | + } |
| 669 | + String failureMessage = devServerFailure.get(); |
| 670 | + if (failureMessage != null) { |
| 671 | + response.setContentType("text/html;charset=utf-8"); |
| 672 | + response.setHeader("Cache-Control", "no-cache"); |
| 673 | + response.getWriter().write("<pre>" + failureMessage + "</pre>"); |
| 674 | + return true; |
| 675 | + } |
| 676 | + if (devServerStartFuture.isDone()) { |
667 | 677 | if (request.getHeader("X-DevModePoll") != null) { |
668 | 678 | // Avoid creating a UI that is thrown away for polling requests |
669 | 679 | response.setContentType("text/html;charset=utf-8"); |
@@ -721,7 +731,7 @@ static boolean handleRequestInternal(VaadinSession session, |
721 | 731 | public boolean serveDevModeRequest(HttpServletRequest request, |
722 | 732 | HttpServletResponse response) throws IOException { |
723 | 733 | // Do not serve requests if dev server starting or failed to start. |
724 | | - if (isDevServerFailedToStart.get() || !devServerStartFuture.isDone() |
| 734 | + if (devServerFailure.get() != null || !devServerStartFuture.isDone() |
725 | 735 | || devServerStartFuture.isCompletedExceptionally()) { |
726 | 736 | return false; |
727 | 737 | } |
|
0 commit comments