Search in sources :

Example 1 with LocationAwareExternalSystemException

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

the class ExternalSystemNotificationManager method processExternalProjectRefreshError.

public void processExternalProjectRefreshError(@NotNull Throwable error, @NotNull String externalProjectName, @NotNull ProjectSystemId externalSystemId) {
    if (myProject.isDisposed() || !myProject.isOpen()) {
        return;
    }
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
    if (!(manager instanceof ExternalSystemConfigurableAware)) {
        return;
    }
    String title = ExternalSystemBundle.message("notification.project.refresh.fail.title", externalSystemId.getReadableName(), externalProjectName);
    String message = ExternalSystemApiUtil.buildErrorMessage(error);
    NotificationCategory notificationCategory = NotificationCategory.ERROR;
    String filePath = null;
    Integer line = null;
    Integer column = null;
    //noinspection ThrowableResultOfMethodCallIgnored
    Throwable unwrapped = RemoteUtil.unwrap(error);
    if (unwrapped instanceof LocationAwareExternalSystemException) {
        LocationAwareExternalSystemException locationAwareExternalSystemException = (LocationAwareExternalSystemException) unwrapped;
        filePath = locationAwareExternalSystemException.getFilePath();
        line = locationAwareExternalSystemException.getLine();
        column = locationAwareExternalSystemException.getColumn();
    }
    NotificationData notificationData = new NotificationData(title, message, notificationCategory, NotificationSource.PROJECT_SYNC, filePath, ObjectUtils.notNull(line, -1), ObjectUtils.notNull(column, -1), false);
    for (ExternalSystemNotificationExtension extension : ExternalSystemNotificationExtension.EP_NAME.getExtensions()) {
        final ProjectSystemId targetExternalSystemId = extension.getTargetExternalSystemId();
        if (!externalSystemId.equals(targetExternalSystemId) && !targetExternalSystemId.equals(ProjectSystemId.IDE)) {
            continue;
        }
        extension.customize(notificationData, myProject, error);
    }
    EditorNotifications.getInstance(myProject).updateAllNotifications();
    showNotification(externalSystemId, notificationData);
}
Also used : ExternalSystemConfigurableAware(com.intellij.openapi.externalSystem.ExternalSystemConfigurableAware) LocationAwareExternalSystemException(com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId)

Example 2 with LocationAwareExternalSystemException

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

the class SimulatedSyncErrors method registerSyncErrorToSimulate.

public static void registerSyncErrorToSimulate(@NotNull Throwable cause, @NotNull File errorFile) {
    verifyIsTestMode();
    LocationAwareExternalSystemException exception = new LocationAwareExternalSystemException(cause.getMessage(), errorFile.getPath());
    exception.initCause(cause);
    store(exception);
}
Also used : LocationAwareExternalSystemException(com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException)

Example 3 with LocationAwareExternalSystemException

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

the class BaseProjectImportErrorHandlerTest method testGetUserFriendlyError.

@Test
public void testGetUserFriendlyError() {
    String causeMsg = "failed to find target current";
    RuntimeException rootCause = new IllegalStateException(causeMsg);
    String locationMsg = "Build file '~/project/build.gradle' line: 86";
    RuntimeException locationError = new RuntimeException(locationMsg, rootCause) {

        @NotNull
        @Override
        public String toString() {
            return LocationAwareException.class.getName() + ": " + super.toString();
        }
    };
    Throwable error = new Throwable(locationError);
    //noinspection ThrowableResultOfMethodCallIgnored
    RuntimeException realCause = myErrorHandler.getUserFriendlyError(error, myProjectPath, null);
    assertTrue(realCause instanceof LocationAwareExternalSystemException);
    LocationAwareExternalSystemException locationAwareExternalSystemException = (LocationAwareExternalSystemException) realCause;
    assertEquals("~/project/build.gradle", locationAwareExternalSystemException.getFilePath());
    assertEquals(Integer.valueOf(-1), locationAwareExternalSystemException.getColumn());
    assertEquals(Integer.valueOf(86), locationAwareExternalSystemException.getLine());
}
Also used : LocationAwareExternalSystemException(com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException) Test(org.junit.Test)

Example 4 with LocationAwareExternalSystemException

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

the class SimulatedSyncErrors method registerSyncErrorToSimulate.

public static void registerSyncErrorToSimulate(@NotNull String errorMessage, @NotNull File errorFile) {
    verifyIsTestMode();
    LocationAwareExternalSystemException exception = new LocationAwareExternalSystemException(errorMessage, errorFile.getPath());
    store(exception);
}
Also used : LocationAwareExternalSystemException(com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException)

Example 5 with LocationAwareExternalSystemException

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

the class ProjectImportErrorHandler method getUserFriendlyError.

@Override
@Nullable
public ExternalSystemException getUserFriendlyError(@NotNull Throwable error, @NotNull String projectPath, @Nullable String buildFilePath) {
    if (error instanceof ExternalSystemException) {
        // This is already a user-friendly error.
        logSyncFailure();
        return (ExternalSystemException) error;
    }
    Pair<Throwable, String> rootCauseAndLocation = getRootCauseAndLocation(error);
    Throwable rootCause = rootCauseAndLocation.getFirst();
    // Create ExternalSystemException or LocationAwareExternalSystemException, so that it goes to SyncErrorHandlers directly.
    String location = rootCauseAndLocation.getSecond();
    String errMessage;
    if (rootCause.getMessage() == null) {
        StringWriter writer = new StringWriter();
        rootCause.printStackTrace(new PrintWriter(writer));
        errMessage = writer.toString();
    } else {
        errMessage = rootCause.getMessage();
    }
    if (!errMessage.isEmpty() && Character.isLowerCase(errMessage.charAt(0))) {
        // Message starts with lower case letter. Sentences should start with uppercase.
        errMessage = "Cause: " + errMessage;
    }
    ExternalSystemException exception = null;
    if (isNotEmpty(location)) {
        Pair<String, Integer> pair = getErrorLocation(location);
        if (pair != null) {
            exception = new LocationAwareExternalSystemException(errMessage, pair.first, pair.getSecond());
        }
    }
    if (exception == null) {
        exception = new ExternalSystemException(errMessage);
    }
    exception.initCause(rootCause);
    return exception;
}
Also used : StringWriter(java.io.StringWriter) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) LocationAwareExternalSystemException(com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException) LocationAwareExternalSystemException(com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException) PrintWriter(java.io.PrintWriter) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

LocationAwareExternalSystemException (com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException)5 ExternalSystemConfigurableAware (com.intellij.openapi.externalSystem.ExternalSystemConfigurableAware)1 ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)1 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Nullable (org.jetbrains.annotations.Nullable)1 Test (org.junit.Test)1