From 1cc28c8df6045b453b14d123b63ec3d0d74c8f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bon=C3=A9r?= Date: Sun, 16 May 2010 20:44:22 +0200 Subject: [PATCH] Improved error handling and message for Config --- akka-core/src/main/scala/config/Config.scala | 21 ++++++++++++-------- config/akka-reference.conf | 12 +++++------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/akka-core/src/main/scala/config/Config.scala b/akka-core/src/main/scala/config/Config.scala index c230d45b5d..fbafdb9b68 100644 --- a/akka-core/src/main/scala/config/Config.scala +++ b/akka-core/src/main/scala/config/Config.scala @@ -8,6 +8,8 @@ import se.scalablesolutions.akka.util.Logging import net.lag.configgy.{Configgy, ParseException} +class ConfigurationException(message: String) extends RuntimeException(message) + /** * @author Jonas Bonér */ @@ -34,16 +36,18 @@ object Config extends Logging { Configgy.configure(configFile) log.info("Config loaded from -Dakka.config=%s", configFile) } catch { - case e: ParseException => throw new IllegalStateException( - "Config could not be loaded from -Dakka.config=" + configFile) + case e: ParseException => throw new ConfigurationException( + "Config could not be loaded from -Dakka.config=" + configFile + + "\n\tdue to: " + e.toString) } } else if (getClass.getClassLoader.getResource("akka.conf") != null) { try { Configgy.configureFromResource("akka.conf", getClass.getClassLoader) log.info("Config loaded from the application classpath.") } catch { - case e: ParseException => throw new IllegalStateException( - "Can't load 'akka.conf' config file from application classpath.") + case e: ParseException => throw new ConfigurationException( + "Can't load 'akka.conf' config file from application classpath," + + "\n\tdue to: " + e.toString) } } else if (HOME.isDefined) { try { @@ -51,12 +55,13 @@ object Config extends Logging { Configgy.configure(configFile) log.info("AKKA_HOME is defined as [%s], config loaded from [%s].", HOME.get, configFile) } catch { - case e: ParseException => throw new IllegalStateException( + case e: ParseException => throw new ConfigurationException( "AKKA_HOME is defined as [" + HOME.get + "] " + - "but the 'akka.conf' config file can not be found at [" + HOME.get + "/config/akka.conf].") + "\n\tbut the 'akka.conf' config file can not be found at [" + HOME.get + "/config/akka.conf]," + + "\n\tdue to: " + e.toString) } } else { - throw new IllegalStateException( + throw new ConfigurationException( "\nCan't load 'akka.conf'." + "\nOne of the three ways of locating the 'akka.conf' file needs to be defined:" + "\n\t1. Define the '-Dakka.config=...' system property option." + @@ -69,7 +74,7 @@ object Config extends Logging { } val CONFIG_VERSION = config.getString("akka.version", "0") - if (VERSION != CONFIG_VERSION) throw new IllegalStateException( + if (VERSION != CONFIG_VERSION) throw new ConfigurationException( "Akka JAR version [" + VERSION + "] is different than the provided config ('akka.conf') version [" + CONFIG_VERSION + "]") val startTime = System.currentTimeMillis diff --git a/config/akka-reference.conf b/config/akka-reference.conf index dbe3abca56..8e0a4a04bc 100644 --- a/config/akka-reference.conf +++ b/config/akka-reference.conf @@ -42,7 +42,7 @@ provider = "from-jndi" # Options: "from-jndi" (means that Akka will try to detect a TransactionManager in the JNDI) # "atomikos" (means that Akka will use the Atomikos based JTA impl in 'akka-jta', # e.g. you need the akka-jta JARs on classpath). - self.timeout = 60000 + timeout = 60000 @@ -53,12 +53,12 @@ authenticator = "sample.security.BasicAuthenticationService" # The authentication service to use. Need to be overridden (uses sample now) #IF you are using a KerberosAuthenticationActor - # - # servicePrincipal = "HTTP/localhost@EXAMPLE.COM" - # keyTabLocation = "URL to keytab" - # kerberosDebug = "true" + # + # servicePrincipal = "HTTP/localhost@EXAMPLE.COM" + # keyTabLocation = "URL to keytab" + # kerberosDebug = "true" # realm = "EXAMPLE.COM" - # + #