Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Anonymise error messages by removing exception handling #856

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
package org.jboss.tools.intellij.openshift.actions;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.redhat.devtools.intellij.common.actions.StructureTreeAction;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryHandler;
import org.jboss.tools.intellij.openshift.telemetry.TelemetrySender;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryService;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
Expand All @@ -24,18 +21,17 @@

import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.PREFIX_ACTION;

public abstract class HelmAction extends StructureTreeAction implements TelemetryHandler {
public abstract class HelmAction extends TelemetryAction {

private static final Logger LOGGER = LoggerFactory.getLogger(HelmAction.class);

protected final TelemetrySender telemetrySender = new TelemetrySender(PREFIX_ACTION + getTelemetryActionName());

protected HelmAction(Class... filters) {
super(filters);
}

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected) {
setTelemetrySender(new TelemetrySender(PREFIX_ACTION + getTelemetryActionName()));
Helm helm = getHelm(anActionEvent);
if (helm == null) {
return;
Expand All @@ -47,7 +43,7 @@ protected Helm getHelm(AnActionEvent anActionEvent) {
try {
return ActionUtils.getApplicationRootNode(anActionEvent).getHelm(true);
} catch (Exception e) {
LOGGER.warn("Could not get helm: " + e.getMessage(), e);
LOGGER.warn("Could not get helm: {}", e.getMessage(), e);
return null;
}
}
Expand All @@ -56,19 +52,4 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
// noop implementation
}

protected abstract String getTelemetryActionName();

public void sendTelemetryResults(TelemetryService.TelemetryResult result) {
telemetrySender.sendTelemetryResults(result);
}

@Override
public void sendTelemetryError(String message) {
telemetrySender.sendTelemetryError(message);
}

@Override
public void sendTelemetryError(Exception exception) {
telemetrySender.sendTelemetryError(exception);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public void sendTelemetryError(String message) {
telemetrySender.sendTelemetryError(message);
}

@Override
public void sendTelemetryError(Exception exception) {
telemetrySender.sendTelemetryError(exception);
}

public void addProperty(String property, @NotNull String value) {
if (telemetrySender != null) {
telemetrySender.addProperty(property, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
NodeUtils.fireModified(node.getParent());
sendTelemetryResults(TelemetryService.TelemetryResult.SUCCESS);
} catch (IOException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
Messages.showWarningDialog("Error: " + e.getLocalizedMessage(), "Delete Binding");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
odo.about();
sendTelemetryResults(TelemetryResult.SUCCESS);
} catch (IOException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "About"));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
sendTelemetryResults(TelemetryResult.ABORTED);
}
} catch (IOException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Login"));
} finally {
clearProcessing(clusterNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
BrowserUtil.open(url);
sendTelemetryResults(TelemetryResult.SUCCESS);
} catch (IOException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Open Console Dashboard");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void doActionPerformed(NamespaceNode namespaceNode, Odo odo, Application
sendTelemetryResults(TelemetryResult.SUCCESS);
} catch (IOException e) {
clearProcessing(namespaceNode);
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Create Component"));
}
},
Expand All @@ -112,8 +112,8 @@ protected void createComponent(Odo odo, CreateComponentModel model)
computeTelemetry(model);
String type = model.getSelectedComponentType() != null ?
model.getSelectedComponentType().getName() : null;
String registry = model.getSelectedComponentType() instanceof DevfileComponentType ?
((DevfileComponentType) model.getSelectedComponentType()).getDevfileRegistry().getName() : null;
String registry = model.getSelectedComponentType() instanceof DevfileComponentType devfileComponentType ?
devfileComponentType.getDevfileRegistry().getName() : null;
String devFile = model.isProjectHasDevfile() ?
Constants.DEVFILE_NAME : null;
odo.createComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void executeDebug() {
runSettings.getConfiguration())).execute(getEnvironment());
sendTelemetryResults(TelemetryResult.SUCCESS);
} catch (ExecutionException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
LOG.error(e.getLocalizedMessage(), e);
}
});
Expand Down Expand Up @@ -182,7 +182,7 @@ private ExecutionEnvironment getEnvironment() {
environment = ExecutionEnvironmentBuilder.create(
DefaultDebugExecutor.getDebugExecutorInstance(), runSettings).build();
} catch (ExecutionException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
LOG.error(e.getLocalizedMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
sendTelemetryResults(TelemetryResult.SUCCESS);
} catch (IOException e) {
clearProcessing(componentNode);
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() ->
Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Delete Component"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
odo.describeComponent(component.getPath());
sendTelemetryResults(TelemetryResult.SUCCESS);
} catch (IOException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Describe"));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ protected FeatureComponentAction(ComponentFeature feature) {
@Override
public boolean isVisible(Object selected) {
boolean visible = super.isVisible(selected);
if (visible && selected instanceof ComponentNode) {
Component component = ((ComponentNode) selected).getComponent();
if (visible && selected instanceof ComponentNode componentNode) {
Component component = componentNode.getComponent();
visible = component.getInfo().getSupportedFeatures().contains(feature.getMode());
}
return visible;
Expand All @@ -54,10 +54,9 @@ public void update(AnActionEvent e) {
super.update(e);
if (e.getPresentation().isVisible() && needCustomizedPresentation()) {
Object node = adjust(getSelected(getTree(e)));
if (!(node instanceof ComponentNode)) {
if (!(node instanceof ComponentNode componentNode)) {
return;
}
ComponentNode componentNode = (ComponentNode) node;
Component component = componentNode.getComponent();
e.getPresentation().setText(getCustomizedPresentation(component));
}
Expand Down Expand Up @@ -104,7 +103,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
});
sendTelemetryResults(TelemetryResult.SUCCESS);
} catch (IOException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), getActionName()));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
clearProcessing(namespaceNode);
} catch (IOException e) {
clearProcessing(namespaceNode);
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Import"));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

import static org.jboss.tools.intellij.openshift.actions.ActionUtils.runWithProgress;
import static org.jboss.tools.intellij.openshift.actions.NodeUtils.clearProcessing;
Expand All @@ -46,7 +45,7 @@ protected String getSelectedTargetComponent(OdoFacade odo, String project, Strin
String targetComponent = null;

List<Component> components = odo.getComponents(project)
.stream().filter(comp -> !comp.getName().equals(component)).collect(Collectors.toList());
.stream().filter(comp -> !comp.getName().equals(component)).toList();
if (!components.isEmpty()) {
if (components.size() == 1) {
targetComponent = components.get(0).getName();
Expand Down Expand Up @@ -78,7 +77,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
clearProcessing(namespaceNode);
} catch (IOException e) {
clearProcessing(namespaceNode);
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Link Component"));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
}
} catch (IOException | NoSuchElementException e) {
clearProcessing(namespaceNode);
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Link Service"));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected void doLog(ComponentNode componentNode, OdoFacade odo, boolean follow)
}
sendTelemetryResults(TelemetryResult.SUCCESS);
} catch (IOException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), getActionName()));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public void actionPerformedOnSelectedObject(AnActionEvent event, Object selected
if (!(selected instanceof HelmRepositoriesNode)) {
return;
}
doActionPerformed((HelmRepositoriesNode) selected, helm, getEventProject(event));
doActionPerformed((HelmRepositoriesNode) selected, getEventProject(event));
}

public void doActionPerformed(HelmRepositoriesNode helmRepositories, Helm helm, Project project) {
public void doActionPerformed(HelmRepositoriesNode helmRepositories, Project project) {
if (helmRepositories == null) {
return;
}
Expand All @@ -52,7 +52,7 @@ public void doActionPerformed(HelmRepositoriesNode helmRepositories, Helm helm,
}

@Override
protected String getTelemetryActionName() {
public String getTelemetryActionName() {
return PREFIX_ACTION + "refresh helm repositories";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public void actionPerformed(AnActionEvent anActionEvent, TreePath[] path, Object
return;
}

runWithProgress((ProgressIndicator progress) -> {
removeRepositories(repositories, helm);
},
runWithProgress((ProgressIndicator progress) -> removeRepositories(repositories, helm),
"Remove Helm Repositories...",
project);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void createProject(String newProject, @NotNull Odo odo) {
sendTelemetryResults(TelemetryResult.SUCCESS);
} catch (IOException | CompletionException e) {
notification.expire();
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Create " + kind));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
NodeUtils.fireRemoved(namespaceNode);
sendTelemetryResults(TelemetryResult.SUCCESS);
} catch (IOException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Delete " + kind));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
sendTelemetryResults(TelemetryResult.ABORTED);
}
} catch (IOException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Create Registry");
}
}
Expand All @@ -63,7 +63,7 @@ private void createDevfileRegistry(AnActionEvent anActionEvent, CreateRegistryDi
ActionUtils.getApplicationTreeStructure(anActionEvent).fireModified(registriesNode);
sendTelemetryResults(TelemetryResult.SUCCESS);
} catch (IOException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(),
"Create registry"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
NodeUtils.fireRemoved(registryNode);
sendTelemetryResults(TelemetryResult.SUCCESS);
} catch (IOException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Delete Registry"));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
sendTelemetryResults(TelemetryService.TelemetryResult.SUCCESS);
} catch (IOException e) {
clearProcessing(namespaceNode);
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Create Service"));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
sendTelemetryResults(TelemetryResult.SUCCESS);
} catch (IOException e) {
clearProcessing(serviceNode);
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Delete Service"));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static org.jboss.tools.intellij.openshift.actions.ActionUtils.runWithProgress;
import static org.jboss.tools.intellij.openshift.actions.NodeUtils.clearProcessing;
Expand Down Expand Up @@ -63,7 +62,7 @@ public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object
UIHelper.executeInUI(() -> Messages.showWarningDialog(message, "Link Component"));
}
} catch (IOException e) {
sendTelemetryError(e);
sendTelemetryError(e.getMessage());
UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Link Component"));
} finally {
clearProcessing(namespaceNode);
Expand Down Expand Up @@ -91,6 +90,6 @@ private Component getComponent(List<Component> components) {
}

private List<Component> getTargetComponents(OdoFacade odo, String project) throws IOException {
return odo.getComponents(project).stream().filter(component -> component.getLiveFeatures().isOnCluster()).collect(Collectors.toList());
return odo.getComponents(project).stream().filter(component -> component.getLiveFeatures().isOnCluster()).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

public interface TelemetryHandler {

void sendTelemetryResults(TelemetryResult result);
void sendTelemetryError(String message);
void sendTelemetryError(Exception exception);
void sendTelemetryResults(TelemetryResult result);

void sendTelemetryError(String message);

}
Loading
Loading