jsevellec / cassandra-unit

Utility tool to load Data into Cassandra to help you writing good isolated JUnit Test into your application
GNU Lesser General Public License v3.0
425 stars 0 forks source link

Misleading error message in YamlConfigurationLoader.loadConfig(): "Invalid yaml" #334

Open tashoyan opened 2 years ago

tashoyan commented 2 years ago

If the method YamlConfigurationLoader.loadConfig() is not able to parse the YAML config file, it throws a ConfigurationException. For example:

org.apache.cassandra.exceptions.ConfigurationException: Invalid yaml: file:/Users/taataar2/workspace/ines-spark-services/ines-spark-apps/target/scala_2.12/cassandra_embedded_db/cu-cassandra-rndport.yaml
 Error: Can't construct a java object for tag:yaml.org,2002:org.apache.cassandra.config.Config; exception=java.lang.reflect.InvocationTargetException
 in 'reader', line 10, column 1:
    cluster_name: 'Test Cluster'
    ^

This error message is misleading - a user may think, that the YAML config file is malformed. In my case, the real cause was an incompatible version of Guava library in the classpath:

java.lang.NoSuchMethodError: com.google.common.collect.Sets.newConcurrentHashSet()Ljava/util/Set;

The problem is, that the ConfigurationException misses the cause:

throw new ConfigurationException("Invalid yaml: " + url + SystemUtils.LINE_SEPARATOR
   +  " Error: " + e.getMessage(), false);

Instead the constructor with the cause argument should be used. Then we could see the underlying exception, that caused the failure.

throw new ConfigurationException(msg, cause)