Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-05-30 23:36:18 +0000
committerKevin Sawicki2011-05-30 23:36:18 +0000
commitd3bab40e0781bb782c66404d434abd28685cdad6 (patch)
tree3c5dbe1456718108e4b84fbbb67619ab20cd6e1a
parent404affd46652f10b3b8f8cc52251d4fb8c42a3f4 (diff)
downloadegit-github-d3bab40e0781bb782c66404d434abd28685cdad6.tar.gz
egit-github-d3bab40e0781bb782c66404d434abd28685cdad6.tar.xz
egit-github-d3bab40e0781bb782c66404d434abd28685cdad6.zip
Use wrapped exception when validating repo settings.
RequestException thrown during repository validation needs to be wrapped in GitHubException to have properly formatted messages displayed in the wizard message area. This change migrates exception handling to always wrap RequestException inside a GitHubException when caught. Change-Id: I464948f7ca14e818e840bf482c301b7d96f5b2ba Signed-off-by: Kevin Sawicki <kevin@github.com>
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHub.java13
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHubException.java13
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java4
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java4
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java4
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueConnector.java12
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistRepositorySettingsPage.java2
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueRepositorySettingsPage.java2
8 files changed, 40 insertions, 14 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHub.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHub.java
index 6206ad0f..064e7629 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHub.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHub.java
@@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.mylyn.internal.github.core;
+import java.io.IOException;
import java.util.regex.Pattern;
import org.eclipse.core.runtime.ILog;
@@ -19,6 +20,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.egit.github.core.Repository;
+import org.eclipse.egit.github.core.client.RequestException;
/**
* GitHub class
@@ -98,6 +100,17 @@ public class GitHub {
}
/**
+ * Create error status from {@link IOException} that wraps it in a
+ * {@link GitHubException} if it is a {@link RequestException}
+ *
+ * @param e
+ * @return status
+ */
+ public static IStatus createWrappedStatus(IOException e) {
+ return createErrorStatus(GitHubException.wrap(e));
+ }
+
+ /**
* Get log
*
* @return log
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHubException.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHubException.java
index a0a58cf7..4048b65d 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHubException.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHubException.java
@@ -29,6 +29,19 @@ public class GitHubException extends IOException {
private static final long serialVersionUID = -1456910662911777231L;
/**
+ * Wraps the given {@link IOException} with a {@link GitHubException} if it
+ * is a {@link RequestException} instance.
+ *
+ * @param exception
+ * @return wrapped exception
+ */
+ public static IOException wrap(IOException exception) {
+ return exception instanceof RequestException ? new GitHubException(
+ (RequestException) exception) : exception;
+
+ }
+
+ /**
* Create GitHub exception from {@link RequestException}
*
* @param cause
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java
index 833f349a..d35abe9f 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java
@@ -69,7 +69,7 @@ public class GistAttachmentHandler extends AbstractTaskAttachmentHandler {
throw new IOException("Unable to obtain raw file URL from Gist"); //$NON-NLS-1$
return new URL(urlAttribute.getValue()).openStream();
} catch (IOException e) {
- throw new CoreException(GitHub.createErrorStatus(e));
+ throw new CoreException(GitHub.createWrappedStatus(e));
}
}
@@ -111,7 +111,7 @@ public class GistAttachmentHandler extends AbstractTaskAttachmentHandler {
file.setContent(output.toString());
service.updateGist(gist);
} catch (IOException e) {
- throw new CoreException(GitHub.createErrorStatus(e));
+ throw new CoreException(GitHub.createWrappedStatus(e));
} finally {
try {
input.close();
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java
index 11f08457..24f6f888 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java
@@ -138,7 +138,7 @@ public class GistConnector extends AbstractRepositoryConnector {
return data;
} catch (IOException e) {
- throw new CoreException(GitHub.createErrorStatus(e));
+ throw new CoreException(GitHub.createWrappedStatus(e));
}
}
@@ -206,7 +206,7 @@ public class GistConnector extends AbstractRepositoryConnector {
collector.accept(data);
}
} catch (IOException e) {
- status = GitHub.createErrorStatus(e);
+ status = GitHub.createWrappedStatus(e);
}
return status;
}
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java
index e68a2900..3e22ecb2 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java
@@ -231,7 +231,7 @@ public class GistTaskDataHandler extends AbstractTaskDataHandler {
try {
gist = service.createGist(gist);
} catch (IOException e) {
- throw new CoreException(GitHub.createErrorStatus(e));
+ throw new CoreException(GitHub.createWrappedStatus(e));
}
response = new RepositoryResponse(ResponseKind.TASK_CREATED,
gist.getId());
@@ -244,7 +244,7 @@ public class GistTaskDataHandler extends AbstractTaskDataHandler {
service.updateGist(gist);
} catch (IOException e) {
- throw new CoreException(GitHub.createErrorStatus(e));
+ throw new CoreException(GitHub.createWrappedStatus(e));
}
response = new RepositoryResponse(ResponseKind.TASK_UPDATED,
taskData.getTaskId());
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueConnector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueConnector.java
index d74fce97..3f978788 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueConnector.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueConnector.java
@@ -33,7 +33,6 @@ import org.eclipse.egit.github.core.Label;
import org.eclipse.egit.github.core.Milestone;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.client.GitHubClient;
-import org.eclipse.egit.github.core.client.RequestException;
import org.eclipse.egit.github.core.service.IssueService;
import org.eclipse.egit.github.core.service.LabelService;
import org.eclipse.egit.github.core.service.MilestoneService;
@@ -43,7 +42,6 @@ import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.commons.net.Policy;
import org.eclipse.mylyn.internal.github.core.GitHub;
-import org.eclipse.mylyn.internal.github.core.GitHubException;
import org.eclipse.mylyn.internal.github.core.QueryUtils;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
@@ -120,7 +118,7 @@ public class IssueConnector extends AbstractRepositoryConnector {
this.repositoryLabels.put(repository, labels);
return labels;
} catch (IOException e) {
- throw new CoreException(GitHub.createErrorStatus(e));
+ throw new CoreException(GitHub.createWrappedStatus(e));
}
}
@@ -173,7 +171,7 @@ public class IssueConnector extends AbstractRepositoryConnector {
this.repositoryMilestones.put(repository, milestones);
return milestones;
} catch (IOException e) {
- throw new CoreException(GitHub.createErrorStatus(e));
+ throw new CoreException(GitHub.createWrappedStatus(e));
}
}
@@ -307,10 +305,8 @@ public class IssueConnector extends AbstractRepositoryConnector {
}
monitor.worked(1);
}
- } catch (RequestException e) {
- result = GitHub.createErrorStatus(new GitHubException(e));
} catch (IOException e) {
- result = GitHub.createErrorStatus(e);
+ result = GitHub.createWrappedStatus(e);
}
monitor.done();
@@ -335,7 +331,7 @@ public class IssueConnector extends AbstractRepositoryConnector {
return taskDataHandler.createTaskData(repository, monitor,
repo.getOwner(), repo.getName(), issue, comments);
} catch (IOException e) {
- throw new CoreException(GitHub.createErrorStatus(e));
+ throw new CoreException(GitHub.createWrappedStatus(e));
}
}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistRepositorySettingsPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistRepositorySettingsPage.java
index a22f50a6..9804ce74 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistRepositorySettingsPage.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistRepositorySettingsPage.java
@@ -22,6 +22,7 @@ import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.service.GistService;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.mylyn.commons.net.AuthenticationType;
+import org.eclipse.mylyn.internal.github.core.GitHubException;
import org.eclipse.mylyn.internal.github.core.gist.GistConnector;
import org.eclipse.mylyn.internal.github.ui.GitHubUi;
import org.eclipse.mylyn.internal.tasks.core.IRepositoryConstants;
@@ -103,6 +104,7 @@ public class GistRepositorySettingsPage extends AbstractRepositorySettingsPage {
monitor.worked(20);
service.getGists(user);
} catch (IOException e) {
+ e = GitHubException.wrap(e);
String message = MessageFormat
.format(Messages.GistRepositorySettingsPage_StatusError,
e.getLocalizedMessage());
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueRepositorySettingsPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueRepositorySettingsPage.java
index 2302a8bf..232ea03b 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueRepositorySettingsPage.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/issue/IssueRepositorySettingsPage.java
@@ -27,6 +27,7 @@ import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.internal.github.core.GitHub;
+import org.eclipse.mylyn.internal.github.core.GitHubException;
import org.eclipse.mylyn.internal.github.ui.GitHubUi;
import org.eclipse.mylyn.internal.tasks.core.IRepositoryConstants;
import org.eclipse.mylyn.tasks.core.TaskRepository;
@@ -153,6 +154,7 @@ public class IssueRepositorySettingsPage extends AbstractRepositorySettingsPage
monitor.worked(50);
service.getIssues(repo.getOwner(), repo.getName(), null);
} catch (IOException e) {
+ e = GitHubException.wrap(e);
String message = MessageFormat
.format(Messages.IssueRepositorySettingsPage_StatusError,
e.getLocalizedMessage());

Back to the top