improve handling of startup error handling

This commit is contained in:
Sebastian Sdorra
2012-04-03 09:48:22 +02:00
parent 7b74ef7820
commit 215b9b3757
6 changed files with 427 additions and 16 deletions

View File

@@ -89,9 +89,16 @@ public class BasicContextProvider implements SCMContextProvider
*/
public BasicContextProvider()
{
baseDirectory = findBaseDirectory();
version = loadVersion();
stage = loadProjectStage();
try
{
baseDirectory = findBaseDirectory();
version = loadVersion();
stage = loadProjectStage();
}
catch (Throwable ex)
{
this.startupError = ex;
}
}
//~--- methods --------------------------------------------------------------
@@ -137,6 +144,18 @@ public class BasicContextProvider implements SCMContextProvider
return stage;
}
/**
* {@inheritDoc}
*
*
* @return
*/
@Override
public Throwable getStartupError()
{
return startupError;
}
/**
* Returns the version of the SCM-Manager. If the version is not set, the
* {@link #DEFAULT_VERSION} is returned.
@@ -182,7 +201,16 @@ public class BasicContextProvider implements SCMContextProvider
if (!directory.exists() &&!directory.mkdirs())
{
throw new IllegalStateException("could not create directory");
String msg = "could not create home directory at ".concat(
directory.getAbsolutePath());
// do not use logger
// http://www.slf4j.org/codes.html#substituteLogger
System.err.println("===================================================");
System.err.append("Error: ").println(msg);
System.err.println("===================================================");
throw new IllegalStateException(msg);
}
return directory;
@@ -319,6 +347,9 @@ public class BasicContextProvider implements SCMContextProvider
/** stage of the current SCM-Manager instance */
private Stage stage;
/** startup exception */
private Throwable startupError;
/** the version of the SCM-Manager */
private String version;
}

View File

@@ -74,6 +74,16 @@ public interface SCMContextProvider extends Closeable
*/
public Stage getStage();
/**
* Returns a exception which is occurred on context startup.
* The method returns null if the start was successful.
*
*
* @return startup exception of null
* @since 1.14
*/
public Throwable getStartupError();
/**
* Returns the version of the SCM-Manager.
*