Skip to content

Commit 9d25613

Browse files
Print logs to console if an exception happens during mill launcher initialization (#5736)
Currently if an exception like #5734 happens while launching the mill daemon there is no logs to look to. This PR adds in-memory logging and outputs that in case of failure. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 0ad2a67 commit 9d25613

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

runner/launcher/src/mill/launcher/MillLauncherMain.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ public static void main(String[] args) throws Exception {
6060
if (runNoServer) {
6161
// start in no-server mode
6262
System.exit(MillProcessLauncher.launchMillNoDaemon(args, outMode));
63-
} else
63+
} else {
64+
var logs = new java.util.ArrayList<String>();
6465
try {
6566
// start in client-server mode
66-
java.util.List<String> optsArgs = new java.util.ArrayList<>();
67-
optsArgs.addAll(MillProcessLauncher.millOpts(outMode));
67+
var optsArgs = new java.util.ArrayList<>(MillProcessLauncher.millOpts(outMode));
6868
Collections.addAll(optsArgs, args);
6969

7070
MillServerLauncher launcher =
@@ -86,18 +86,25 @@ public void prepareDaemonDir(Path daemonDir) throws Exception {
8686

8787
var daemonDir0 = Paths.get(outDir, OutFiles.millDaemon);
8888
String javaHome = MillProcessLauncher.javaHome(outMode);
89-
// No logging.
90-
Consumer<String> log = ignored -> {};
89+
Consumer<String> log = logs::add;
9190
var exitCode = launcher.run(daemonDir0, javaHome, log).exitCode;
9291
if (exitCode == ClientUtil.ExitServerCodeWhenVersionMismatch()) {
9392
exitCode = launcher.run(daemonDir0, javaHome, log).exitCode;
9493
}
9594
System.exit(exitCode);
9695
} catch (Exception e) {
97-
System.err.println("Mill client failed with unknown exception");
96+
System.err.println("Mill client failed with unknown exception.");
97+
System.err.println();
98+
99+
System.err.println("Exception:");
100+
//noinspection CallToPrintStackTrace
98101
e.printStackTrace();
102+
System.err.println();
103+
System.err.println("Logs:");
104+
logs.forEach(System.err::println);
99105
System.exit(1);
100106
}
107+
}
101108
}
102109

103110
private static boolean containsBspFlag(String[] args) {

0 commit comments

Comments
 (0)