improve exception handling

This commit is contained in:
Sebastian Sdorra
2011-10-19 09:02:03 +02:00
parent f9ff425db3
commit f1752c0403
4 changed files with 29 additions and 30 deletions

View File

@@ -66,6 +66,15 @@ import javax.xml.bind.JAXBException;
public class AbstractHgHandler public class AbstractHgHandler
{ {
/** Field description */
public static final String ENV_NODE = "HG_NODE";
/** Field description */
public static final String ENV_PAGE_LIMIT = "SCM_PAGE_LIMIT";
/** Field description */
public static final String ENV_PAGE_START = "SCM_PAGE_START";
/** Field description */ /** Field description */
public static final String ENV_PATH = "SCM_PATH"; public static final String ENV_PATH = "SCM_PATH";
@@ -81,21 +90,12 @@ public class AbstractHgHandler
/** Field description */ /** Field description */
public static final String ENV_REVISION = "SCM_REVISION"; public static final String ENV_REVISION = "SCM_REVISION";
/** Field description */
public static final String ENV_PAGE_LIMIT = "SCM_PAGE_LIMIT";
/** Field description */
public static final String ENV_PAGE_START = "SCM_PAGE_START";
/** Field description */ /** Field description */
public static final String ENV_REVISION_END = "SCM_REVISION_END"; public static final String ENV_REVISION_END = "SCM_REVISION_END";
/** Field description */ /** Field description */
public static final String ENV_REVISION_START = "SCM_REVISION_START"; public static final String ENV_REVISION_START = "SCM_REVISION_START";
/** Field description */
public static final String ENV_NODE = "HG_NODE";
/** the logger for AbstractHgHandler */ /** the logger for AbstractHgHandler */
private static final Logger logger = private static final Logger logger =
LoggerFactory.getLogger(AbstractHgHandler.class); LoggerFactory.getLogger(AbstractHgHandler.class);
@@ -294,10 +294,11 @@ public class AbstractHgHandler
* @return * @return
* *
* @throws IOException * @throws IOException
* @throws RepositoryException
*/ */
protected <T> T getResultFromScript(Class<T> resultType, protected <T> T getResultFromScript(Class<T> resultType,
String scriptResource) String scriptResource)
throws IOException throws IOException, RepositoryException
{ {
return getResultFromScript(resultType, scriptResource, return getResultFromScript(resultType, scriptResource,
new HashMap<String, String>()); new HashMap<String, String>());
@@ -315,10 +316,11 @@ public class AbstractHgHandler
* @return * @return
* *
* @throws IOException * @throws IOException
* @throws RepositoryException
*/ */
protected <T> T getResultFromScript(Class<T> resultType, protected <T> T getResultFromScript(Class<T> resultType,
String scriptResource, Map<String, String> extraEnv) String scriptResource, Map<String, String> extraEnv)
throws IOException throws IOException, RepositoryException
{ {
Process p = createPythonProcess(extraEnv); Process p = createPythonProcess(extraEnv);
T result = null; T result = null;
@@ -340,6 +342,8 @@ public class AbstractHgHandler
catch (JAXBException ex) catch (JAXBException ex)
{ {
logger.error("could not parse result", ex); logger.error("could not parse result", ex);
throw new RepositoryException("could not parse result", ex);
} }
finally finally
{ {
@@ -412,7 +416,7 @@ public class AbstractHgHandler
{ {
env.put(ENV_PENDING, directory.getAbsolutePath()); env.put(ENV_PENDING, directory.getAbsolutePath());
if ( extraEnv.containsKey( ENV_REVISION_START ) ) if (extraEnv.containsKey(ENV_REVISION_START))
{ {
env.put(ENV_NODE, extraEnv.get(ENV_REVISION_START)); env.put(ENV_NODE, extraEnv.get(ENV_REVISION_START));
} }

View File

@@ -93,9 +93,11 @@ public class HgBlameViewer extends AbstractHgHandler implements BlameViewer
* @return * @return
* *
* @throws IOException * @throws IOException
* @throws RepositoryException
*/ */
@Override @Override
public BlameResult getBlame(String revision, String path) throws IOException public BlameResult getBlame(String revision, String path)
throws IOException, RepositoryException
{ {
AssertUtil.assertIsNotEmpty(path); AssertUtil.assertIsNotEmpty(path);

View File

@@ -104,10 +104,11 @@ public class HgChangesetViewer extends AbstractHgHandler
* @return * @return
* *
* @throws IOException * @throws IOException
* @throws RepositoryException
*/ */
@Override @Override
public ChangesetPagingResult getChangesets(int start, int max) public ChangesetPagingResult getChangesets(int start, int max)
throws IOException throws IOException, RepositoryException
{ {
return getChangesets(String.valueOf(start), String.valueOf(max), null, return getChangesets(String.valueOf(start), String.valueOf(max), null,
null); null);
@@ -125,10 +126,11 @@ public class HgChangesetViewer extends AbstractHgHandler
* @return * @return
* *
* @throws IOException * @throws IOException
* @throws RepositoryException
*/ */
public ChangesetPagingResult getChangesets(String pageStart, public ChangesetPagingResult getChangesets(String pageStart,
String pageLimit, String revisionStart, String revisionEnd) String pageLimit, String revisionStart, String revisionEnd)
throws IOException throws IOException, RepositoryException
{ {
Map<String, String> env = new HashMap<String, String>(); Map<String, String> env = new HashMap<String, String>();
@@ -150,9 +152,10 @@ public class HgChangesetViewer extends AbstractHgHandler
* @return * @return
* *
* @throws IOException * @throws IOException
* @throws RepositoryException
*/ */
public ChangesetPagingResult getChangesets(String startNode, String endNode) public ChangesetPagingResult getChangesets(String startNode, String endNode)
throws IOException throws IOException, RepositoryException
{ {
return getChangesets(null, null, startNode, endNode); return getChangesets(null, null, startNode, endNode);
} }

View File

@@ -33,15 +33,9 @@
package sonia.scm.repository; package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -56,10 +50,6 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent
/** Field description */ /** Field description */
public static final String REV_TIP = "tip"; public static final String REV_TIP = "tip";
/** the logger for HgRepositoryHookEvent */
private static final Logger logger =
LoggerFactory.getLogger(HgRepositoryHookEvent.class);
//~--- constructors --------------------------------------------------------- //~--- constructors ---------------------------------------------------------
/** /**
@@ -104,9 +94,9 @@ public class HgRepositoryHookEvent extends AbstractRepositoryHookEvent
changesets = result.getChangesets(); changesets = result.getChangesets();
} }
} }
catch (IOException ex) catch (Exception ex)
{ {
logger.error("could not load changesets", ex); throw new RuntimeException("could not load changesets", ex);
} }
} }