From: <sha...@us...> - 2012-04-29 16:25:20
|
Revision: 3666 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3666&view=rev Author: shadowtm Date: 2012-04-29 16:25:14 +0000 (Sun, 29 Apr 2012) Log Message: ----------- Improved the way we were handling/outputting error messages to the console for the CLI interface. Modified Paths: -------------- trunk/components-core/pom.xml trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java trunk/pom.xml Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2012-04-29 15:58:36 UTC (rev 3665) +++ trunk/components-core/pom.xml 2012-04-29 16:25:14 UTC (rev 3666) @@ -225,6 +225,10 @@ <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </dependency> </dependencies> Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-04-29 15:58:36 UTC (rev 3665) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-04-29 16:25:14 UTC (rev 3666) @@ -27,24 +27,16 @@ import java.util.List; import java.util.Map.Entry; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Layout; -import org.apache.log4j.Level; +import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; import org.apache.xmlbeans.XmlObject; -import org.dllearner.Info; import org.dllearner.configuration.IConfiguration; import org.dllearner.configuration.spring.ApplicationContextBuilder; import org.dllearner.configuration.spring.DefaultApplicationContextBuilder; import org.dllearner.configuration.util.SpringConfigurationXMLBeanConverter; import org.dllearner.confparser3.ConfParserConfiguration; import org.dllearner.confparser3.ParseException; -import org.dllearner.core.AbstractCELA; -import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.LearningAlgorithm; -import org.dllearner.core.ReasoningMethodUnsupportedException; +import org.dllearner.core.*; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.Files; import org.springframework.context.ApplicationContext; @@ -170,10 +162,10 @@ List<Resource> springConfigResources = new ArrayList<Resource>(); - //DL-Learner Configuration Object - IConfiguration configuration = new ConfParserConfiguration(confFile); + try { + //DL-Learner Configuration Object + IConfiguration configuration = new ConfParserConfiguration(confFile); - try { ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); ApplicationContext context = builder.buildApplicationContext(configuration,springConfigResources); @@ -191,7 +183,15 @@ cli.run(); } catch (Exception e) { String stacktraceFileName = "log/error.log"; - logger.error("An Error Occurred During Processing. Terminating DL-Learner...and writing stacktrace to: " + stacktraceFileName); + + //Find the primary cause of the exception. + Throwable primaryCause = findPrimaryCause(e); + + // Get the Root Error Message + logger.error("An Error Has Occurred During Processing."); + logger.error(primaryCause.getMessage()); + + logger.error("Terminating DL-Learner...and writing stacktrace to: " + stacktraceFileName); FileOutputStream fos = new FileOutputStream(stacktraceFileName); PrintStream ps = new PrintStream(fos); e.printStackTrace(ps); @@ -199,7 +199,30 @@ } - public void setContext(ApplicationContext context) { + /** + * Find the primary cause of the specified exception. + * + * @param e The exception to analyze + * @return The primary cause of the exception. + */ + private static Throwable findPrimaryCause(Exception e) { + // The throwables from the stack of the exception + Throwable[] throwables = ExceptionUtils.getThrowables(e); + + //Look For a Component Init Exception and use that as the primary cause of failure, if we find it + int componentInitExceptionIndex = ExceptionUtils.indexOfThrowable(e, ComponentInitException.class); + + Throwable primaryCause; + if(componentInitExceptionIndex > -1) { + primaryCause = throwables[componentInitExceptionIndex]; + }else { + //No Component Init Exception on the Stack Trace, so we'll use the root as the primary cause. + primaryCause = ExceptionUtils.getRootCause(e); + } + return primaryCause; + } + + public void setContext(ApplicationContext context) { this.context = context; } Modified: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java 2012-04-29 15:58:36 UTC (rev 3665) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java 2012-04-29 16:25:14 UTC (rev 3666) @@ -14,7 +14,6 @@ import org.springframework.beans.factory.support.ManagedSet; import java.util.Collection; -import java.util.StringTokenizer; /** * Created by IntelliJ IDEA. Modified: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java 2012-04-29 15:58:36 UTC (rev 3665) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java 2012-04-29 16:25:14 UTC (rev 3666) @@ -59,7 +59,6 @@ try { context.refresh(); } catch (BeanCreationException e) { - logger.error("There was a problem creating the bean named \"" + e.getBeanName() + "\" - Check your configuration file and try again."); throw new RuntimeException(e); } catch (Exception e) { logger.error("There was a problem initializing the components...shutting down."); Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-04-29 15:58:36 UTC (rev 3665) +++ trunk/pom.xml 2012-04-29 16:25:14 UTC (rev 3666) @@ -478,7 +478,13 @@ <version>2.6.0</version> </dependency> - </dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.6</version> + </dependency> + + </dependencies> </dependencyManagement> <repositories> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |