Search in sources :

Example 6 with ExternalSystemException

use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.

the class GradleNotificationExtensionTest method testCustomizeWithExternalSystemException.

public void testCustomizeWithExternalSystemException() throws Exception {
    ExternalSystemException error = new ExternalSystemException("Testing");
    // myHandler1 returns 'true', myHandler2 should not be invoked.
    when(myHandler1.handleError(error, myNotification, myProject)).thenReturn(true);
    myNotificationExtension.customize(myNotification, myProject, error);
    verify(mySyncMessages, times(1)).removeProjectMessages();
    verify(myHandler1, times(1)).handleError(error, myNotification, myProject);
    verify(myHandler2, never()).handleError(error, myNotification, myProject);
}
Also used : ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException)

Example 7 with ExternalSystemException

use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.

the class ProjectImportErrorHandlerTest method getUserFriendlyError.

// https://code.google.com/p/android/issues/detail?id=226506
@Test
public void getUserFriendlyError() {
    ProjectImportErrorHandler errorHandler = new ProjectImportErrorHandler();
    IllegalStateException cause = new IllegalStateException("Failed to find Build Tools revision 24.0.3");
    BuildException error = new BuildException("Could not run build action.", cause);
    ExternalSystemException userFriendlyError = errorHandler.getUserFriendlyError(error, "fakeProjectPath", null);
    assertNotNull(userFriendlyError);
    assertEquals("Failed to find Build Tools revision 24.0.3", userFriendlyError.getMessage());
}
Also used : ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) BuildException(org.gradle.tooling.BuildException) Test(org.junit.Test)

Example 8 with ExternalSystemException

use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project android by JetBrains.

the class ProjectImportErrorHandlerTest method getUserFriendlyErrorWithLowerCase.

// https://code.google.com/p/android/issues/detail?id=226870
@Test
public void getUserFriendlyErrorWithLowerCase() {
    ProjectImportErrorHandler errorHandler = new ProjectImportErrorHandler();
    Throwable error = new Throwable("some random sync error");
    ExternalSystemException userFriendlyError = errorHandler.getUserFriendlyError(error, "fakeProjectPath", null);
    assertNotNull(userFriendlyError);
    assertEquals("Cause: some random sync error", userFriendlyError.getMessage());
}
Also used : ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) Test(org.junit.Test)

Example 9 with ExternalSystemException

use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project intellij-community by JetBrains.

the class ExternalSystemTaskManagerWrapper method executeTasks.

@Override
public void executeTasks(@NotNull ExternalSystemTaskId id, @NotNull List<String> taskNames, @NotNull String projectPath, @Nullable S settings, @Nullable String jvmAgentSetup) throws RemoteException, ExternalSystemException {
    myProgressManager.onStart(id, projectPath);
    try {
        getDelegate().executeTasks(id, taskNames, projectPath, settings, jvmAgentSetup);
        myProgressManager.onSuccess(id);
    } catch (ExternalSystemException e) {
        myProgressManager.onFailure(id, e);
        throw e;
    } catch (Exception e) {
        myProgressManager.onFailure(id, e);
        throw new ExternalSystemException(e);
    } finally {
        myProgressManager.onEnd(id);
    }
}
Also used : ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) RemoteException(java.rmi.RemoteException)

Example 10 with ExternalSystemException

use of com.intellij.openapi.externalSystem.model.ExternalSystemException in project intellij-community by JetBrains.

the class BaseProjectImportErrorHandler method getUserFriendlyError.

@NotNull
@Override
public ExternalSystemException getUserFriendlyError(@NotNull Throwable error, @NotNull String projectPath, @Nullable String buildFilePath) {
    if (error instanceof ExternalSystemException) {
        // This is already a user-friendly error.
        return (ExternalSystemException) error;
    }
    LOG.info(String.format("Failed to import Gradle project at '%1$s'", projectPath), error);
    if (error instanceof ProcessCanceledException) {
        return new ExternalSystemException("Project import was cancelled");
    }
    Pair<Throwable, String> rootCauseAndLocation = getRootCauseAndLocation(error);
    //noinspection ThrowableResultOfMethodCallIgnored
    Throwable rootCause = rootCauseAndLocation.getFirst();
    String location = rootCauseAndLocation.getSecond();
    if (location == null && !StringUtil.isEmpty(buildFilePath)) {
        location = String.format("Build file: '%1$s'", buildFilePath);
    }
    if (rootCause instanceof UnsupportedVersionException) {
        String msg = "You are using unsupported version of Gradle.";
        msg += ('\n' + FIX_GRADLE_VERSION);
        // Location of build.gradle is useless for this error. Omitting it.
        return createUserFriendlyError(msg, null);
    }
    final String rootCauseMessage = rootCause.getMessage();
    // CommandLineArgumentException class can be loaded by different classloaders
    if (rootCause.getClass().getName().equals(CommandLineArgumentException.class.getName())) {
        if (StringUtil.contains(rootCauseMessage, "Unknown command-line option '--include-build'")) {
            String msg = String.format("Gradle composite build support available for Gradle 3.1 or better version (<a href=\"%s\">Fix Gradle settings</a>)", OpenGradleSettingsCallback.ID);
            return createUserFriendlyError(msg, location, OpenGradleSettingsCallback.ID);
        }
    }
    final String rootCauseText = rootCause.toString();
    if (StringUtil.startsWith(rootCauseText, "org.gradle.api.internal.MissingMethodException")) {
        String method = parseMissingMethod(rootCauseText);
        String msg = "Build script error, unsupported Gradle DSL method found: '" + method + "'!";
        msg += (EMPTY_LINE + "Possible causes could be:  ");
        msg += String.format("%s  - you are using Gradle version where the method is absent (<a href=\"%s\">Fix Gradle settings</a>)", '\n', OpenGradleSettingsCallback.ID);
        msg += String.format("%s  - you didn't apply Gradle plugin which provides the method (<a href=\"%s\">Apply Gradle plugin</a>)", '\n', ApplyGradlePluginCallback.ID);
        msg += String.format("%s  - or there is a mistake in a build script (<a href=\"%s\">Goto source</a>)", '\n', GotoSourceNotificationCallback.ID);
        return createUserFriendlyError(msg, location, OpenGradleSettingsCallback.ID, ApplyGradlePluginCallback.ID, GotoSourceNotificationCallback.ID);
    }
    if (rootCause instanceof OutOfMemoryError) {
        // The OutOfMemoryError happens in the Gradle daemon process.
        String msg = "Out of memory";
        if (rootCauseMessage != null && !rootCauseMessage.isEmpty()) {
            msg = msg + ": " + rootCauseMessage;
        }
        if (msg.endsWith("Java heap space")) {
            msg += ". Configure Gradle memory settings using '-Xmx' JVM option (e.g. '-Xmx2048m'.)";
        } else if (!msg.endsWith(".")) {
            msg += ".";
        }
        msg += EMPTY_LINE + OPEN_GRADLE_SETTINGS;
        // Location of build.gradle is useless for this error. Omitting it.
        return createUserFriendlyError(msg, null);
    }
    if (rootCause instanceof ClassNotFoundException) {
        String msg = String.format("Unable to load class '%1$s'.", rootCauseMessage) + EMPTY_LINE + UNEXPECTED_ERROR_FILE_BUG;
        // Location of build.gradle is useless for this error. Omitting it.
        return createUserFriendlyError(msg, null);
    }
    if (rootCause instanceof UnknownHostException) {
        String msg = String.format("Unknown host '%1$s'.", rootCauseMessage) + EMPTY_LINE + "Please ensure the host name is correct. " + SET_UP_HTTP_PROXY;
        // Location of build.gradle is useless for this error. Omitting it.
        return createUserFriendlyError(msg, null);
    }
    if (rootCause instanceof ConnectException) {
        String msg = rootCauseMessage;
        if (msg != null && msg.contains("timed out")) {
            msg += msg.endsWith(".") ? " " : ". ";
            msg += SET_UP_HTTP_PROXY;
            return createUserFriendlyError(msg, null);
        }
    }
    if (rootCause instanceof RuntimeException) {
        String msg = rootCauseMessage;
        if (msg != null && UNSUPPORTED_GRADLE_VERSION_ERROR_PATTERN.matcher(msg).matches()) {
            if (!msg.endsWith(".")) {
                msg += ".";
            }
            msg += EMPTY_LINE + OPEN_GRADLE_SETTINGS;
            // Location of build.gradle is useless for this error. Omitting it.
            return createUserFriendlyError(msg, null);
        }
    }
    final String errMessage;
    if (rootCauseMessage == null) {
        StringWriter writer = new StringWriter();
        rootCause.printStackTrace(new PrintWriter(writer));
        errMessage = writer.toString();
    } else {
        errMessage = rootCauseMessage;
    }
    return createUserFriendlyError(errMessage, location);
}
Also used : UnknownHostException(java.net.UnknownHostException) StringWriter(java.io.StringWriter) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) CommandLineArgumentException(org.gradle.cli.CommandLineArgumentException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) UnsupportedVersionException(org.gradle.tooling.UnsupportedVersionException) ConnectException(java.net.ConnectException) PrintWriter(java.io.PrintWriter) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)20 File (java.io.File)6 IOException (java.io.IOException)5 NotNull (org.jetbrains.annotations.NotNull)5 LocationAwareExternalSystemException (com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException)4 Nullable (org.jetbrains.annotations.Nullable)3 Application (com.intellij.openapi.application.Application)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Test (org.junit.Test)2 Message (com.android.ide.common.blame.Message)1 SyncErrorHandler (com.android.tools.idea.gradle.project.sync.errors.SyncErrorHandler)1 MessageType (com.android.tools.idea.gradle.project.sync.messages.MessageType)1 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)1 SyncMessages (com.android.tools.idea.gradle.project.sync.messages.SyncMessages)1 LocalProperties (com.android.tools.idea.gradle.util.LocalProperties)1 PositionInFile (com.android.tools.idea.gradle.util.PositionInFile)1 ValidationResult (com.android.tools.idea.sdk.SdkPaths.ValidationResult)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 AndroidStudioEvent (com.google.wireless.android.sdk.stats.AndroidStudioEvent)1