1 16 package scriptella.execution; 17 18 import scriptella.configuration.Location; 19 import scriptella.core.EtlCancelledException; 20 import scriptella.core.ExceptionInterceptor; 21 import scriptella.expression.Expression; 22 import scriptella.spi.ProviderException; 23 import scriptella.util.StringUtils; 24 25 import java.io.PrintWriter ; 26 import java.io.StringWriter ; 27 28 29 35 public class EtlExecutorException extends Exception { 36 private ProviderException lastProvider; 37 private Throwable lastExpression; 38 private Location lastElementLocation; 39 private String message; 40 private boolean cancelled; 41 42 public EtlExecutorException(Throwable cause) { 43 super(cause); 44 45 for (Throwable ex = cause; ex != null; ex = ex.getCause()) { 46 if (isExpression(ex)) { 47 lastExpression = ex; 48 } 49 50 if (ex instanceof ProviderException) { 51 ProviderException providerEx = (ProviderException) ex; 52 lastProvider = providerEx; 53 } 54 55 if (ex instanceof ExceptionInterceptor.ExecutionException) { 56 lastElementLocation = ((ExceptionInterceptor.ExecutionException) ex).getLocation(); 57 } 58 59 if (ex instanceof EtlCancelledException || ex instanceof InterruptedException ) { 60 cancelled = true; 61 } 62 } 63 64 final StringWriter out = new StringWriter (); 65 PrintWriter pw = new PrintWriter (out); if ((lastProvider==null || lastElementLocation==null) && cause != null && cause.getMessage() != null) { 67 pw.println(cause.getMessage()); 68 } 69 if (lastElementLocation != null) { 70 pw.print("Location: "); 71 pw.println(lastElementLocation); 72 } 73 if (lastProvider != null) { 74 pw.print(lastProvider.getProviderName() + " provider exception: "); 75 pw.println(lastProvider.getMessage()); 76 77 if (lastProvider.getErrorStatement() != null) { 78 pw.print("Error statement: "); 79 pw.print(lastProvider.getErrorStatement()); 80 pw.println(); 81 } 82 pw.println("Error codes: " + lastProvider.getErrorCodes()); 83 Throwable nativeException = lastProvider.getNativeException(); 84 if (nativeException != null) { 85 pw.print("Driver exception: "); 86 pw.print(nativeException.toString()); 87 pw.println(); 88 } 89 } 90 if (lastExpression != null) { 91 pw.print("Expression exception: "); 92 pw.print(lastExpression.getMessage()); 93 pw.println(); 94 } 95 this.message = StringUtils.consoleFormat(out.toString()); 96 } 97 98 99 public String getMessage() { 100 return message; 101 } 102 103 public ProviderException getLastProvider() { 104 return lastProvider; 105 } 106 107 public Throwable getLastExpression() { 108 return lastExpression; 109 } 110 111 public Location getLastElementLocation() { 112 return lastElementLocation; 113 } 114 115 public boolean isCancelled() { 116 return cancelled; 117 } 118 119 private static boolean isExpression(final Throwable cause) { 120 return cause instanceof Expression.ParseException || 121 cause instanceof Expression.EvaluationException; 122 } 123 124 } 125 | Popular Tags |