Skip to content

Commit

Permalink
Fix whats new action error handing and record telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
Flanker32 committed Sep 30, 2020
1 parent 5364b0a commit 598f9bb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,13 @@ public void runActivity(@NotNull Project project) {
}

private void initializeWhatsNew(Project project) {
try {
WhatsNewManager.INSTANCE.showWhatsNew(false, project);
} catch (IOException e) {
// swallow this exception as shown whats new in startup should not block users
LOG.error(e.getMessage(), e);
}
EventUtil.executeWithLog(SYSTEM, SHOW_WHATS_NEW,
operation -> {
WhatsNewManager.INSTANCE.showWhatsNew(true, project);
},
error -> {
// swallow this exception as shown whats new in startup should not block users
});
}

private void initializeFeedbackNotification(Project myProject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.microsoft.azuretools.ijidea.utility.AzureAnAction;
import com.microsoft.azuretools.telemetrywrapper.ErrorType;
import com.microsoft.azuretools.telemetrywrapper.EventUtil;
import com.microsoft.azuretools.telemetrywrapper.Operation;
import com.microsoft.intellij.helpers.WhatsNewManager;
import com.microsoft.intellij.util.PluginUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import static com.microsoft.azuretools.telemetry.TelemetryConstants.SHOW_WHATS_NEW;
import static com.microsoft.azuretools.telemetry.TelemetryConstants.SYSTEM;

public class ShowWhatsNewAction extends AzureAnAction {

Expand All @@ -42,9 +45,18 @@ public boolean onActionPerformed(@NotNull final AnActionEvent anActionEvent, @Nu
final Project project = anActionEvent.getProject();
try {
WhatsNewManager.INSTANCE.showWhatsNew(true, project);
} catch (IOException e) {
} catch (Exception e) {
EventUtil.logError(operation, ErrorType.systemError, e, null, null);
PluginUtil.showInfoNotificationProject(project, FAILED_TO_LOAD_WHATS_NEW, e.getMessage());
}
return true;
}

protected String getServiceName(AnActionEvent event) {
return SYSTEM;
}

protected String getOperationName(AnActionEvent event) {
return SHOW_WHATS_NEW;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.LightVirtualFile;
import com.microsoft.azure.hdinsight.common.StreamUtil;
import com.microsoft.tooling.msservices.components.DefaultLoader;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
Expand Down Expand Up @@ -83,7 +84,7 @@ private void createAndShowWhatsNew(Project project, FileEditorManager fileEditor
virtualFile.setContent(null, content, true);
virtualFile.putUserData(WHAT_S_NEW_ID, WHAT_S_NEW_CONSTANT);
virtualFile.setWritable(false);
ApplicationManager.getApplication().invokeLater(() -> {
DefaultLoader.getIdeHelper().invokeAndWait(() -> {
final FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, true, true);
for (FileEditor fileEditor : fileEditors) {
if (fileEditor instanceof MarkdownSplitEditor) {
Expand All @@ -92,7 +93,7 @@ private void createAndShowWhatsNew(Project project, FileEditorManager fileEditor
true);
}
}
}, ModalityState.defaultModalityState());
});
}

private String getWhatsNewContent() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public class TelemetryConstants {
public static final String PROVISION_A_CLUSTER = "provision-a-cluster";
public static final String DELETE_A_CLUSTER = "delete-a-cluster";
public static final String UPDATE_A_CLUSTER = "update-a-cluster";
public static final String SHOW_WHATS_NEW = "show-whats-new";

// property name
public static final String WEBAPP_DEPLOY_TO_SLOT = "webappDeployToSlot";
Expand Down

0 comments on commit 598f9bb

Please sign in to comment.