11package bblfsh .bash ;
22
33import java .io .IOException ;
4+ import java .io .StringWriter ;
5+ import java .io .PrintWriter ;
46import java .util .ArrayList ;
57
68public 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