Skip to content

Commit d50188f

Browse files
author
Juanjo Alvarez
committed
Fix broken error control
Signed-off-by: Juanjo Alvarez <[email protected]>
1 parent 159be54 commit d50188f

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

native/src/main/java/bblfsh/bash/Driver.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package bblfsh.bash;
22

33
import java.io.IOException;
4+
import java.io.StringWriter;
5+
import java.io.PrintWriter;
46
import java.util.ArrayList;
57

68
public class Driver {
@@ -19,13 +21,23 @@ public void run() throws DriverException, CloseException {
1921
}
2022
}
2123

24+
private void printStdError(Throwable ex) {
25+
StringWriter outError = new StringWriter();
26+
ex.printStackTrace(new PrintWriter(outError));
27+
String errorString = outError.toString();
28+
System.err.println(errorString);
29+
}
30+
2231
public void processOne() throws DriverException, CloseException {
2332
Request request;
2433
try {
2534
request = this.reader.read();
26-
} catch (CloseException ex) {
27-
throw ex;
35+
final Response response = this.processRequest(request);
36+
this.writer.write(response);
2837
} catch (Exception ex) {
38+
// Show the error on stderr too to help with debugging
39+
printStdError(ex);
40+
2941
final Response response = createFatalResponse(ex);
3042
try {
3143
this.writer.write(response);
@@ -35,13 +47,6 @@ public void processOne() throws DriverException, CloseException {
3547

3648
return;
3749
}
38-
39-
final Response response = this.processRequest(request);
40-
try {
41-
this.writer.write(response);
42-
} catch (IOException ex) {
43-
throw new DriverException("exception writing response", ex);
44-
}
4550
}
4651

4752
private Response createFatalResponse(final Exception e) {

0 commit comments

Comments
 (0)