[CORDA-1596] Improve error message when CorDapp schema changes (#4506)

* Raise schema exceptions with better error

* Add test and use new exceptions
This commit is contained in:
JamesHR3
2019-01-29 08:17:05 +00:00
committed by GitHub
parent 6b0b8b394c
commit 22462cc1e8
2 changed files with 45 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import co.paralleluniverse.strands.Strand
import net.corda.core.internal.NamedCacheFactory
import net.corda.core.schemas.MappedSchema
import net.corda.core.utilities.contextLogger
import org.hibernate.tool.schema.spi.SchemaManagementException
import rx.Observable
import rx.Subscriber
import rx.subjects.UnicastSubject
@ -101,7 +102,14 @@ class CordaPersistence(
private val defaultIsolationLevel = databaseConfig.transactionIsolationLevel
val hibernateConfig: HibernateConfiguration by lazy {
transaction {
HibernateConfiguration(schemas, databaseConfig, attributeConverters, jdbcUrl, cacheFactory, customClassLoader)
try {
HibernateConfiguration(schemas, databaseConfig, attributeConverters, jdbcUrl, cacheFactory, customClassLoader)
} catch (e: Exception) {
when (e) {
is SchemaManagementException -> throw HibernateSchemaChangeException("Incompatible schema change detected. Please run the node with database.initialiseSchema=true. Reason: ${e.message}", e)
else -> throw HibernateConfigException("Could not create Hibernate configuration: ${e.message}", e)
}
}
}
}
@ -339,3 +347,7 @@ private fun Throwable.hasSQLExceptionCause(): Boolean =
}
class CouldNotCreateDataSourceException(override val message: String?, override val cause: Throwable? = null) : Exception()
class HibernateSchemaChangeException(override val message: String?, override val cause: Throwable? = null): Exception()
class HibernateConfigException(override val message: String?, override val cause: Throwable? = null): Exception()