private static Throwable getRootCause(Throwable t) { Throwable rootCause = ExceptionUtils.getRootCause(t); if (rootCause == null) { rootCause = t; } return rootCause; } }
/** * Gets a short message summarising the root cause exception. * <p> * The message returned is of the form * {ClassNameWithoutPackage}: {ThrowableMessage} * * @param th the throwable to get a message for, null returns empty string * @return the message, non-null * @since Commons Lang 2.2 */ public static String getRootCauseMessage(Throwable th) { Throwable root = ExceptionUtils.getRootCause(th); root = (root == null ? th : root); return getMessage(root); }
private String getJobExceptionStack(Throwable e) { if (e == null) { return ""; } Throwable cause = ExceptionUtils.getRootCause(e); if (cause != null) { return ExceptionUtils.getFullStackTrace(cause); } else { return ExceptionUtils.getFullStackTrace(e); } }
private boolean processException(Throwable e, int i) { if (!(ExceptionUtils.getRootCause(e) instanceof InterruptedException)) { logger.error("retry {} ,something error happened. caused by {}", (i + 1), ExceptionUtils.getFullStackTrace(e)); try { alarmService.sendAlarm(new AlarmMessage(ExceptionUtils.getFullStackTrace(e), alarmReceiver)); } catch (Throwable e1) { logger.error("send alarm failed. ", e1); } try { Thread.sleep(retryInterval); } catch (InterruptedException e1) { exception = new YuGongException(e1); Thread.currentThread().interrupt(); return true; } } else { // interrupt事件,响应退出 return true; } return false; }
@Override public GatewayFilter apply(Config config) { return (exchange, chain) -> { ServerWebExchange filteredExchange = ofNullable((Throwable) exchange .getAttribute(HYSTRIX_EXECUTION_EXCEPTION_ATTR)) .map(executionException -> { ServerHttpRequest.Builder requestBuilder = exchange.getRequest().mutate(); requestBuilder.header(config.executionExceptionTypeHeaderName, executionException.getClass().getName()); requestBuilder.header(config.executionExceptionMessageHeaderName, executionException.getMessage()); ofNullable(getRootCause(executionException)).ifPresent(rootCause -> { requestBuilder.header(config.rootCauseExceptionTypeHeaderName, rootCause.getClass().getName()); requestBuilder.header(config.rootCauseExceptionMessageHeaderName, rootCause.getMessage()); }); return exchange.mutate().request(requestBuilder.build()).build(); }).orElse(exchange); return chain.filter(filteredExchange); }; }
startServing(" (gained leadership)", " (lost leadership)"); } catch (Throwable t) { Throwable root = ExceptionUtils.getRootCause(t); if ((root != null && (root instanceof InterruptedException)) || Thread.interrupted()) { return;
nrOfRows += 1; } catch (DataFileWriter.AppendWriteException awe) { Throwable rootCause = ExceptionUtils.getRootCause(awe); if(rootCause instanceof UnresolvedUnionException) { UnresolvedUnionException uue = (UnresolvedUnionException) rootCause;
} else if (ExceptionUtils.getRootCause(exception) instanceof InterruptedException) { progressTracer.update(context.getTableMeta().getFullName(), ProgressStatus.FAILED); logger.info("table[{}] is interrpt ,current status:{} !", context.getTableMeta()
@Override public void close() throws Exception { if (!closed) { final RequestMessage msg = RequestMessage.build(Tokens.OPS_CLOSE) .addArg(Tokens.ARGS_SIDE_EFFECT, serverSideEffect) .addArg(Tokens.ARGS_HOST, host) .processor("traversal").create(); try { client.submitAsync(msg).get(); closed = true; } catch (Exception ex) { final Throwable root = ExceptionUtils.getRootCause(ex); throw new RuntimeException("Error on closing side effects", null == root ? ex : root); } } }
@Test(expected = QueryExecutionException.class) public void testLoadJdbcWrongKey() throws Exception { try { testResult(db, "CALL apoc.load.jdbc('derbyy','PERSON')", (r) -> {}); } catch (QueryExecutionException e) { Throwable except = ExceptionUtils.getRootCause(e); assertTrue(except instanceof RuntimeException); assertEquals("No apoc.jdbc.derbyy.url url specified", except.getMessage()); throw e; } }
@Test(expected = QueryExecutionException.class) public void testExportGraphGraphMLQueryGephiWithStringCaption() throws Exception { File output = new File(directory, "query.graphml"); try { TestUtil.testCall(db, "call apoc.export.graphml.query('MATCH p=()-[r]->() RETURN p limit 1000',{file},{useTypes:true, format: 'gephi', caption: 'name'}) ", map("file", output.getAbsolutePath()), (r) -> {}); } catch (QueryExecutionException e) { Throwable except = ExceptionUtils.getRootCause(e); TestCase.assertTrue(except instanceof RuntimeException); assertEquals("Only array of Strings are allowed!", except.getMessage()); throw e; } }
@Test(expected = QueryExecutionException.class) public void testImportGraphMLWithNoImportConfig() throws Exception { File output = new File(directory, "all.graphml"); try { TestUtil.testCall(db, "CALL apoc.import.graphml({file},{readLabels:true})", map("file", output.getAbsolutePath()), (r) -> assertResults(output, r, "database")); } catch (QueryExecutionException e) { Throwable except = ExceptionUtils.getRootCause(e); TestCase.assertTrue(except instanceof RuntimeException); assertEquals("Import from files not enabled, please set apoc.import.file.enabled=true in your neo4j.conf", except.getMessage()); throw e; } }
@Test(expected = QueryExecutionException.class) public void testExportGraphGraphMLTypesWithNoExportConfig() throws Exception { File output = new File(directory, "all.graphml"); try { TestUtil.testCall(db, "CALL apoc.export.graphml.all({file},null)", map("file", output.getAbsolutePath()), (r) -> assertResults(output, r, "database")); } catch (QueryExecutionException e) { Throwable except = ExceptionUtils.getRootCause(e); TestCase.assertTrue(except instanceof RuntimeException); assertEquals("Export to files not enabled, please set apoc.export.file.enabled=true in your neo4j.conf", except.getMessage()); throw e; } }
@Test(expected = QueryExecutionException.class) public void testLoadJsonByUrlInConfigFileWrongKey() throws Exception { try { testResult(db, "CALL apoc.load.json({key})",map("key","foo"), (r) -> {}); } catch (QueryExecutionException e) { Throwable except = ExceptionUtils.getRootCause(e); assertTrue(except instanceof RuntimeException); assertEquals("Can't read url or key invalid URL (foo) as json: no protocol: foo", except.getMessage()); throw e; } } }
@Test(expected = QueryExecutionException.class) public void testLoadJdbcUrlWithSpecialCharWithEmptyUserWithAuthentication() throws Exception { try { db.execute("CALL apoc.load.jdbc({url}, 'PERSON',[],{credentials:{user:'',password:'Ap0c!#Db'}})", Util.map("url","jdbc:derby:derbyDB")).next(); } catch (IllegalArgumentException e) { Throwable except = ExceptionUtils.getRootCause(e); assertTrue(except instanceof IllegalArgumentException); assertEquals("In config param credentials must be passed both user and password.", except.getMessage()); throw e; } }
@Test(expected = QueryExecutionException.class) public void testLoadXmlPreventXXEVulnerabilityThrowsQueryExecutionException() { try { testResult(db, "CALL apoc.load.xml('file:src/test/resources/xml/xxe.xml', '/catalog/book[genre=\"Computer\"]') yield value as result", (r) -> {}); } catch (QueryExecutionException e) { // We want test that the cause of the exception is SAXParseException with the correct cause message Throwable except = ExceptionUtils.getRootCause(e); assertTrue(except instanceof SAXParseException); assertEquals("DOCTYPE is disallowed when the feature \"http://apache.org/xml/features/disallow-doctype-decl\" set to true.", except.getMessage()); throw e; } }
@Test @LoadGraphWith(MODERN) @IgnoreEngine(TraversalEngine.Type.STANDARD) public void g_V_hasLabelXpersonX_pageRank_byXrankX_byXbothEX_rank_profile() { final Traversal<Vertex, TraversalMetrics> traversal = get_g_V_hasLabelXpersonX_pageRank_byXrankX_byXbothEX_rank_profile(); //printTraversalForm(traversal); try { traversal.iterate(); fail("Should have tossed an exception because multi-OLAP is unsolvable"); } catch (Exception ex) { assertTrue(ex instanceof VerificationException || ExceptionUtils.getRootCause(ex) instanceof VerificationException); } }
@Test(expected = QueryExecutionException.class) public void testLoadJdbcUrlWithSpecialCharWithoutUserWithAuthentication() throws Exception { try { db.execute("CALL apoc.load.jdbc({url}, 'PERSON',[],{credentials:{password:'Ap0c!#Db'}})", Util.map("url","jdbc:derby:derbyDB")).next(); } catch (IllegalArgumentException e) { Throwable except = ExceptionUtils.getRootCause(e); assertTrue(except instanceof IllegalArgumentException); assertEquals("In config param credentials must be passed both user and password.", except.getMessage()); throw e; } }
@Test(expected = QueryExecutionException.class) public void testLoadJdbcUrlWithSpecialCharWithEmptyPasswordWithAuthentication() throws Exception { try { db.execute("CALL apoc.load.jdbc({url}, 'PERSON',[],{credentials:{user:'apoc',password:''}})", Util.map("url","jdbc:derby:derbyDB")).next(); } catch (IllegalArgumentException e) { Throwable except = ExceptionUtils.getRootCause(e); assertTrue(except instanceof IllegalArgumentException); assertEquals("In config param credentials must be passed both user and password.", except.getMessage()); throw e; } }
@Test(expected = QueryExecutionException.class) public void testLoadJdbcUrlWithSpecialCharWithoutPasswordWithAuthentication() throws Exception { try { db.execute("CALL apoc.load.jdbc({url}, 'PERSON',[],{credentials:{user:'apoc'}})", Util.map("url","jdbc:derby:derbyDB")).next(); } catch (IllegalArgumentException e) { Throwable except = ExceptionUtils.getRootCause(e); assertTrue(except instanceof IllegalArgumentException); assertEquals("In config param credentials must be passed both user and password.", except.getMessage()); throw e; } }