1
1
package bblfsh .bash ;
2
2
3
3
import java .io .IOException ;
4
+ import java .io .StringWriter ;
5
+ import java .io .PrintWriter ;
4
6
import java .util .ArrayList ;
5
7
6
8
public class Driver {
@@ -19,13 +21,23 @@ public void run() throws DriverException, CloseException {
19
21
}
20
22
}
21
23
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
+
22
31
public void processOne () throws DriverException , CloseException {
23
32
Request request ;
24
33
try {
25
34
request = this .reader .read ();
26
- } catch ( CloseException ex ) {
27
- throw ex ;
35
+ final Response response = this . processRequest ( request );
36
+ this . writer . write ( response ) ;
28
37
} catch (Exception ex ) {
38
+ // Show the error on stderr too to help with debugging
39
+ printStdError (ex );
40
+
29
41
final Response response = createFatalResponse (ex );
30
42
try {
31
43
this .writer .write (response );
@@ -35,13 +47,6 @@ public void processOne() throws DriverException, CloseException {
35
47
36
48
return ;
37
49
}
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
- }
45
50
}
46
51
47
52
private Response createFatalResponse (final Exception e ) {
0 commit comments