From 590141163fd312bedd8594cf87f82812986d09b6 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Fri, 13 Jan 2017 10:41:27 +0900 Subject: [PATCH] LfsProtocolServlet: Improve error on getLargeFileRepository failure Externalize the error message and make it more specific. Also emit an error log. Change-Id: Ie7b1c90c54673bfb8e133fb0aa19a117d4ca6587 Signed-off-by: David Pursehouse Signed-off-by: Matthias Sohn --- org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF | 3 ++- .../eclipse/jgit/lfs/server/LfsProtocolServlet.java | 11 ++++++++++- .../org/eclipse/jgit/lfs/internal/LfsText.properties | 1 + .../src/org/eclipse/jgit/lfs/internal/LfsText.java | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF b/org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF index 554b223a1..08cc18935 100644 --- a/org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF @@ -33,4 +33,5 @@ Import-Package: com.google.gson;version="[2.2.4,3.0.0)", org.eclipse.jgit.nls;version="[4.7.0,4.8.0)", org.eclipse.jgit.transport.http;version="[4.7.0,4.8.0)", org.eclipse.jgit.transport.http.apache;version="[4.7.0,4.8.0)", - org.eclipse.jgit.util;version="[4.7.0,4.8.0)" + org.eclipse.jgit.util;version="[4.7.0,4.8.0)", + org.slf4j;version="[1.7.0,2.0.0)" diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java index 0dffb8df0..b741693fd 100644 --- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java +++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java @@ -59,6 +59,7 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; +import java.text.MessageFormat; import java.util.List; import javax.servlet.ServletException; @@ -75,6 +76,9 @@ import org.eclipse.jgit.lfs.errors.LfsRepositoryReadOnly; import org.eclipse.jgit.lfs.errors.LfsUnauthorized; import org.eclipse.jgit.lfs.errors.LfsUnavailable; import org.eclipse.jgit.lfs.errors.LfsValidationError; +import org.eclipse.jgit.lfs.internal.LfsText; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; @@ -88,6 +92,8 @@ import com.google.gson.GsonBuilder; * @since 4.3 */ public abstract class LfsProtocolServlet extends HttpServlet { + private static Logger LOG = LoggerFactory + .getLogger(LfsProtocolServlet.class); private static final long serialVersionUID = 1L; @@ -183,7 +189,10 @@ public abstract class LfsProtocolServlet extends HttpServlet { try { repo = getLargeFileRepository(request, path); if (repo == null) { - throw new LfsException("unexpected error"); //$NON-NLS-1$ + String error = MessageFormat + .format(LfsText.get().lfsFailedToGetRepository, path); + LOG.error(error); + throw new LfsException(error); } res.setStatus(SC_OK); TransferHandler handler = TransferHandler diff --git a/org.eclipse.jgit.lfs/resources/org/eclipse/jgit/lfs/internal/LfsText.properties b/org.eclipse.jgit.lfs/resources/org/eclipse/jgit/lfs/internal/LfsText.properties index aa089da11..e08e28cc5 100644 --- a/org.eclipse.jgit.lfs/resources/org/eclipse/jgit/lfs/internal/LfsText.properties +++ b/org.eclipse.jgit.lfs/resources/org/eclipse/jgit/lfs/internal/LfsText.properties @@ -8,3 +8,4 @@ repositoryNotFound=Repository {0} not found repositoryReadOnly=Repository {0} is read-only lfsUnavailable=LFS is not available for repository {0} lfsUnathorized=Not authorized to perform operation {0} on repository {1} +lfsFailedToGetRepository=failed to get repository {0} diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsText.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsText.java index 4260fcd0c..44595887c 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsText.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsText.java @@ -68,4 +68,5 @@ public class LfsText extends TranslationBundle { /***/ public String repositoryReadOnly; /***/ public String lfsUnavailable; /***/ public String lfsUnathorized; + /***/ public String lfsFailedToGetRepository; }