Make BazelWorker not swallow exceptions if the transpiler aborted abnormally.
*/
package com.google.j2cl.bazel;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.io.Files;
import com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest;
import com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse;
import com.google.j2cl.common.Problems;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
@@ -77,12 +81,15 @@ public abstract class BazelWorker {
private static void runStandaloneWorker(Supplier<BazelWorker> workerSupplier, String[] args)
throws IOException {
// This is a single invocation of builder that exits after it processed the request.
- try (PrintWriter err = new PrintWriter(System.err)) {
+
+ // DO NOT close the err PrintWriter, since it will close the System.err stream and swallow
+ // whatever gets sent to it, e.g. exception stack trace.
+ PrintWriter err =
+ new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)));
int exitCode = execute(workerSupplier, expandFlagFile(args), err);
err.flush();
System.exit(exitCode);
}
- }
private static void runPersistentWorker(Supplier<BazelWorker> workerSupplier) throws IOException {
while (true) {
