Adding conditional logic to pull out root cause to a couple diagnosers.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@320918 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-10-13 21:03:54 +00:00
parent 7a1e687879
commit ed17ce3aba
4 changed files with 49 additions and 0 deletions

View File

@ -21,6 +21,8 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.usability.diagnostics.DiagnosisUtils;
import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
import java.io.IOException;
public class ArtifactResolverDiagnoser
implements ErrorDiagnoser
{
@ -43,6 +45,13 @@ public class ArtifactResolverDiagnoser
message.append( "\n\n" );
message.append( exception.getMessage() );
IOException ioe = (IOException) DiagnosisUtils.getFromCausality( exception, IOException.class );
if ( ioe != null && exception.getMessage().indexOf( ioe.getMessage() ) < 0 )
{
message.append( "\n\nCaused by I/O exception: " ).append( ioe.getMessage() );
}
if ( !wagonManager.isOnline() )
{
message.append( "\n" ).append( SystemWarnings.getOfflineWarning() );

View File

@ -56,6 +56,22 @@ public class MojoExecutionExceptionDiagnoser
message.append( "\n\n" ).append( longMessage );
}
Throwable directCause = mee.getCause();
if ( directCause != null )
{
message.append( "\n" );
String directCauseMessage = directCause.getMessage();
if ( directCauseMessage != null && mee.getMessage().indexOf( directCauseMessage ) < 0 )
{
message.append( "\nEmbedded error: " ).append( directCauseMessage );
}
DiagnosisUtils.appendRootCauseIfPresentAndUnique( directCause, message, false );
}
return message.toString();
}

View File

@ -77,4 +77,24 @@ public final class DiagnosisUtils
return null;
}
public static void appendRootCauseIfPresentAndUnique( Throwable error, StringBuffer message, boolean includeTypeInfo )
{
Throwable root = DiagnosisUtils.getRootCause( error );
if ( root != null && root != error )
{
String rootMsg = root.getMessage();
if ( rootMsg != null && error.getMessage().indexOf(rootMsg) < 0 )
{
message.append( "\nRoot message: " ).append( rootMsg );
if ( includeTypeInfo )
{
message.append( "\nRoot error type: " ).append( root.getClass().getName() );
}
}
}
}
}

View File

@ -129,6 +129,10 @@ public class ErrorDiagnostics
message.append( error.getMessage() );
message.append( "\nError type: " ).append( error.getClass().getName() );
DiagnosisUtils.appendRootCauseIfPresentAndUnique( error, message, true );
return message.toString();
}