From db5a17fa9e2697a88458c59b610f02e0cf4dfc08 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 2 Apr 2013 21:57:23 +0200 Subject: [PATCH 1/2] send mercurial hook error messages to client --- .../sonia/scm/web/HgHookCallbackServlet.java | 39 +++++++++++++++++++ .../resources/sonia/scm/python/scmhooks.py | 6 +++ 2 files changed, 45 insertions(+) diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/web/HgHookCallbackServlet.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/web/HgHookCallbackServlet.java index 23ba07ffc4..90ff22974d 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/web/HgHookCallbackServlet.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/web/HgHookCallbackServlet.java @@ -35,6 +35,7 @@ package sonia.scm.web; //~--- non-JDK imports -------------------------------------------------------- +import com.google.common.io.Closeables; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; @@ -61,6 +62,7 @@ import sonia.scm.util.Util; //~--- JDK imports ------------------------------------------------------------ import java.io.IOException; +import java.io.PrintWriter; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -294,6 +296,10 @@ public class HgHookCallbackServlet extends HttpServlet response.sendError(HttpServletResponse.SC_NOT_FOUND); } + catch (Exception ex) + { + sendError(response, ex); + } } /** @@ -350,6 +356,39 @@ public class HgHookCallbackServlet extends HttpServlet } } + /** + * Method description + * + * + * @param response + * @param ex + * + * @throws IOException + */ + private void sendError(HttpServletResponse response, Exception ex) + throws IOException + { + logger.warn("hook ended with exception", ex); + response.setStatus(HttpServletResponse.SC_CONFLICT); + + String msg = ex.getMessage(); + + if (msg != null) + { + PrintWriter writer = null; + + try + { + writer = response.getWriter(); + writer.println(msg); + } + finally + { + Closeables.closeQuietly(writer); + } + } + } + //~--- get methods ---------------------------------------------------------- /** diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py index e414aad9f7..28f20e6cc2 100644 --- a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py @@ -54,6 +54,12 @@ def callHookUrl(ui, repo, hooktype, node): abort = False else: ui.warn( "ERROR: scm-hook failed with error code " + str(conn.code) + "\n" ) + except urllib2.URLError, e: + msg = e.read(); + if len(msg) > 0: + ui.warn( "ERROR: " + msg) + else: + ui.warn( "ERROR: scm-hook failed with error code " + str(e.getcode()) + "\n" ) except ValueError: ui.warn( "scm-hook failed with an exception\n" ) return abort From a0a36c6e48004a8d2daaf0d256e3bcbd10b0f925 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 2 Apr 2013 21:58:05 +0200 Subject: [PATCH 2/2] close branch issue-333