From 21a82f3191ea28fe66bbce7189fba45dab2ee59e Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Sat, 21 Oct 2023 15:16:49 +0200 Subject: [PATCH] Improve error handling --- .../AddCompileDependencyHandler.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bundles/com.salesforce.bazel.eclipse.ui/src/com/salesforce/bazel/eclipse/ui/commands/classpath/AddCompileDependencyHandler.java b/bundles/com.salesforce.bazel.eclipse.ui/src/com/salesforce/bazel/eclipse/ui/commands/classpath/AddCompileDependencyHandler.java index 6f0e8f12..0926d182 100644 --- a/bundles/com.salesforce.bazel.eclipse.ui/src/com/salesforce/bazel/eclipse/ui/commands/classpath/AddCompileDependencyHandler.java +++ b/bundles/com.salesforce.bazel.eclipse.ui/src/com/salesforce/bazel/eclipse/ui/commands/classpath/AddCompileDependencyHandler.java @@ -2,11 +2,13 @@ import static com.salesforce.bazel.eclipse.ui.utils.JavaSearchUtil.createScopeIncludingAllWorkspaceProjectsButSelected; import static java.lang.String.format; +import static java.util.stream.Collectors.joining; import static org.eclipse.core.runtime.SubMonitor.convert; import java.lang.reflect.InvocationTargetException; import java.util.HashSet; import java.util.LinkedHashSet; +import java.util.List; import java.util.Set; import org.eclipse.core.commands.ExecutionEvent; @@ -14,6 +16,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jdt.core.IJavaElement; @@ -25,6 +28,7 @@ import org.eclipse.jdt.core.dom.IMethodBinding; import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.Modifier; +import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext; import org.eclipse.jdt.ui.IJavaElementSearchConstants; import org.eclipse.jdt.ui.JavaUI; @@ -34,6 +38,7 @@ import org.eclipse.ui.ISources; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.statushandlers.StatusManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -261,9 +266,18 @@ protected Job createJob(IProject project, ExecutionEvent event) throws CoreExcep return null; } - } catch (InvocationTargetException | CoreException e) { - LOG.error("Add Dependency Failed: Error collecting dependency information. {}", e.getMessage(), e); - MessageDialog.openError(activeShell, "Add Dependency Failed", "Please check the logs for more details!"); + } catch (InvocationTargetException | CoreException | AbortCompilation e) { + StatusManager.getManager() + .handle( + Status.error( + List.of( + "Unable to add the dependency.", + "", + "Please check the error log for details. In the event of resolution problems please add missing libraries to the project view!") + .stream() + .collect(joining(System.lineSeparator())), + e), + StatusManager.SHOW | StatusManager.LOG); } catch (InterruptedException e) { throw new OperationCanceledException(); }