/** * Converts a {@link Throwable} object into a flattened list of texts including its stack trace * and the stack traces of the nested causes. * @param ex a {@link Throwable} object * @return a flattened list of texts including the {@link Throwable} object's stack trace * and the stack traces of the nested causes. */ public static List<String> toString(Throwable ex) { return toString(ex, null); }
private static List<String> toString(Throwable cause, StackTraceElement[] parent) { StackTraceElement[] trace = cause.getStackTrace(); int m = trace.length - 1; if (parent != null) { int n = parent.length - 1; while (m >= 0 && n >= 0 && trace[m].equals(parent[n])) { m--; n--; } } List<String> detail = enroll(cause, trace, m); cause = cause.getCause(); if (cause != null) { detail.addAll(toString(cause, trace)); } return detail; }
/** * Converts the specified {@link Exception} object into a {@link TStatus} object * @param e a {@link Exception} object * @return a {@link TStatus} object */ public static TStatus toTStatus(Exception e) { if (e instanceof HiveSQLException) { return ((HiveSQLException)e).toTStatus(); } TStatus tStatus = new TStatus(TStatusCode.ERROR_STATUS); tStatus.setErrorMessage(e.getMessage()); tStatus.setInfoMessages(toString(e)); return tStatus; }
public void testExceptionConversion() { Exception ex1 = createException(); ex1.initCause(createSimpleCause()); Throwable ex = HiveSQLException.toCause(HiveSQLException.toString(ex1)); Assert.assertSame(RuntimeException.class, ex.getClass()); Assert.assertEquals("exception1", ex.getMessage()); Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass()); Assert.assertEquals("exception2", ex.getCause().getMessage()); } };
/** * Tests the conversion of the exception that the class type of one of the causes * doesn't exist. The stack trace text is generated on the server and passed to JDBC * client. It's possible that some cause types don't exist on the client and HiveSQLException * can't convert them and use RunTimeException instead. */ @Test public void testExceptionWithMissingTypeOnClient() { Exception ex1 = new UnsupportedOperationException(); ex1.initCause(createSimpleCause()); List<String> details = HiveSQLException.toString(ex1); // Simulate an unknown type String[] tokens = details.get(0).split(":"); tokens[0] = "*DummyException"; details.set(0, StringUtils.join(tokens, ":")); Throwable ex = HiveSQLException.toCause(details); Assert.assertEquals(RuntimeException.class, ex.getClass()); }
/** * Tests the conversion between the exception text with nested cause and * the Throwable object */ @Test public void testNestedException() { Exception ex1 = createException(); ex1.initCause(createNestedCause()); Throwable ex = HiveSQLException.toCause(HiveSQLException.toString(ex1)); Assert.assertSame(RuntimeException.class, ex.getClass()); Assert.assertEquals("exception1", ex.getMessage()); Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass()); Assert.assertEquals("exception2", ex.getCause().getMessage()); Assert.assertSame(Exception.class, ex.getCause().getCause().getClass()); Assert.assertEquals("exception3", ex.getCause().getCause().getMessage()); }
/** * Tests the conversion between the exception text with the simple cause and the * Throwable object */ @Test public void testExceptionMarshalling() throws Exception { Exception ex1 = createException(); ex1.initCause(createSimpleCause()); Throwable ex = HiveSQLException.toCause(HiveSQLException.toString(ex1)); Assert.assertSame(RuntimeException.class, ex.getClass()); Assert.assertEquals("exception1", ex.getMessage()); Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass()); Assert.assertEquals("exception2", ex.getCause().getMessage()); }
/** * Tests the conversion of the exception with unknown source */ @Test public void testExceptionWithUnknownSource() { Exception ex1 = createException(); ex1.initCause(createSimpleCause()); List<String> details = HiveSQLException.toString(ex1); // Simulate the unknown source String[] tokens = details.get(1).split(":"); tokens[2] = null; tokens[3] = "-1"; details.set(1, StringUtils.join(tokens, ":")); Throwable ex = HiveSQLException.toCause(details); Assert.assertSame(RuntimeException.class, ex.getClass()); Assert.assertEquals("exception1", ex.getMessage()); Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass()); Assert.assertEquals("exception2", ex.getCause().getMessage()); }
/** * Tests the conversion from a regular exception to the TStatus object */ @Test public void testExceptionToTStatus() { Exception ex1 = createException(); ex1.initCause(createSimpleCause()); TStatus status = HiveSQLException.toTStatus(ex1); Assert.assertEquals(TStatusCode.ERROR_STATUS, status.getStatusCode()); Assert.assertEquals(ex1.getMessage(), status.getErrorMessage()); Assert.assertEquals(HiveSQLException.toString(ex1), status.getInfoMessages()); }
/** * Converts current object to a {@link TStatus} object * @return a {@link TStatus} object */ public TStatus toTStatus() { // TODO: convert sqlState, etc. TStatus tStatus = new TStatus(TStatusCode.ERROR_STATUS); tStatus.setSqlState(getSQLState()); tStatus.setErrorCode(getErrorCode()); tStatus.setErrorMessage(getMessage()); tStatus.setInfoMessages(toString(this)); return tStatus; }
/** * Tests the conversion from a HiveSQLException exception to the TStatus object */ @Test public void testHiveSQLExceptionToTStatus() { String expectedMessage = "reason"; String expectedSqlState = "sqlState"; int expectedVendorCode = 10; Exception ex1 = new HiveSQLException(expectedMessage, expectedSqlState, expectedVendorCode, createSimpleCause()); TStatus status = HiveSQLException.toTStatus(ex1); Assert.assertEquals(TStatusCode.ERROR_STATUS, status.getStatusCode()); Assert.assertEquals(expectedSqlState, status.getSqlState()); Assert.assertEquals(expectedMessage, status.getErrorMessage()); Assert.assertEquals(HiveSQLException.toString(ex1), status.getInfoMessages()); }
/** * Converts a {@link Throwable} object into a flattened list of texts including its stack trace * and the stack traces of the nested causes. * @param ex a {@link Throwable} object * @return a flattened list of texts including the {@link Throwable} object's stack trace * and the stack traces of the nested causes. */ public static List<String> toString(Throwable ex) { return toString(ex, null); }
/** * Converts a {@link Throwable} object into a flattened list of texts including its stack trace * and the stack traces of the nested causes. * @param ex a {@link Throwable} object * @return a flattened list of texts including the {@link Throwable} object's stack trace * and the stack traces of the nested causes. */ public static List<String> toString(Throwable ex) { return toString(ex, null); }
/** * Converts a {@link Throwable} object into a flattened list of texts including its stack trace * and the stack traces of the nested causes. * @param ex a {@link Throwable} object * @return a flattened list of texts including the {@link Throwable} object's stack trace * and the stack traces of the nested causes. */ public static List<String> toString(Throwable ex) { return toString(ex, null); }
/** * Converts a {@link Throwable} object into a flattened list of texts including its stack trace * and the stack traces of the nested causes. * @param ex a {@link Throwable} object * @return a flattened list of texts including the {@link Throwable} object's stack trace * and the stack traces of the nested causes. */ public static List<String> toString(Throwable ex) { return toString(ex, null); }
/** * Converts a {@link Throwable} object into a flattened list of texts including its stack trace * and the stack traces of the nested causes. * @param ex a {@link Throwable} object * @return a flattened list of texts including the {@link Throwable} object's stack trace * and the stack traces of the nested causes. */ public static List<String> toString(Throwable ex) { return toString(ex, null); }
/** * Converts current object to a {@link TStatus} object * @return a {@link TStatus} object */ public TStatus toTStatus() { // TODO: convert sqlState, etc. TStatus tStatus = new TStatus(TStatusCode.ERROR_STATUS); tStatus.setSqlState(getSQLState()); tStatus.setErrorCode(getErrorCode()); tStatus.setErrorMessage(getMessage()); tStatus.setInfoMessages(toString(this)); return tStatus; }
/** * Converts current object to a {@link TStatus} object * @return a {@link TStatus} object */ public TStatus toTStatus() { // TODO: convert sqlState, etc. TStatus tStatus = new TStatus(TStatusCode.ERROR_STATUS); tStatus.setSqlState(getSQLState()); tStatus.setErrorCode(getErrorCode()); tStatus.setErrorMessage(getMessage()); tStatus.setInfoMessages(toString(this)); return tStatus; }
/** * Converts current object to a {@link TStatus} object * @return a {@link TStatus} object */ public TStatus toTStatus() { // TODO: convert sqlState, etc. TStatus tStatus = new TStatus(TStatusCode.ERROR_STATUS); tStatus.setSqlState(getSQLState()); tStatus.setErrorCode(getErrorCode()); tStatus.setErrorMessage(getMessage()); tStatus.setInfoMessages(toString(this)); return tStatus; }
/** * Converts current object to a {@link TStatus} object * @return a {@link TStatus} object */ public TStatus toTStatus() { // TODO: convert sqlState, etc. TStatus tStatus = new TStatus(TStatusCode.ERROR_STATUS); tStatus.setSqlState(getSQLState()); tStatus.setErrorCode(getErrorCode()); tStatus.setErrorMessage(getMessage()); tStatus.setInfoMessages(toString(this)); return tStatus; }