Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
guw committed Oct 21, 2023
1 parent 8c7b7b0 commit 21a82f3
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

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;
import org.eclipse.core.expressions.IEvaluationContext;
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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 21a82f3

Please sign in to comment.