mirror of
https://github.com/ACINQ/eclair.git
synced 2025-03-12 19:01:39 +01:00
Add logs and exception for checkDBCompatibility
This commit is contained in:
parent
33a352e4a0
commit
83dd1b96ac
4 changed files with 12 additions and 5 deletions
|
@ -30,7 +30,7 @@ object DBCompatChecker extends Logging {
|
|||
def checkDBCompatibility(nodeParams: NodeParams): Unit =
|
||||
Try(nodeParams.db.channels.listLocalChannels()) match {
|
||||
case Success(_) => {}
|
||||
case Failure(_) => throw IncompatibleDBException
|
||||
case Failure(exception) => throw IncompatibleDBException(exception)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -303,6 +303,6 @@ case object BitcoinWalletDisabledException extends RuntimeException("bitcoind mu
|
|||
|
||||
case object EmptyAPIPasswordException extends RuntimeException("must set a password for the json-rpc api")
|
||||
|
||||
case object IncompatibleDBException extends RuntimeException("database is not compatible with this version of eclair")
|
||||
case class IncompatibleDBException(cause: Throwable) extends RuntimeException("database is not compatible with this version of eclair", cause)
|
||||
|
||||
case object IncompatibleNetworkDBException extends RuntimeException("network database is not compatible with this version of eclair")
|
||||
|
|
|
@ -65,10 +65,17 @@ trait JdbcUtils {
|
|||
*
|
||||
* TODO: we should use an scala.Iterator instead
|
||||
*/
|
||||
def codecSequence[T](rs: ResultSet, codec: Codec[T]): Seq[T] = {
|
||||
def codecSequence[T](rs: ResultSet, codec: Codec[T], onError: String => Unit = { _ => Unit }): Seq[T] = {
|
||||
var q: Queue[T] = Queue()
|
||||
while (rs.next()) {
|
||||
q = q :+ codec.decode(BitVector(rs.getBytes("data"))).require.value
|
||||
val data = BitVector(rs.getBytes("data"))
|
||||
try {
|
||||
q = q :+ codec.decode(data).require.value
|
||||
} catch {
|
||||
case t: Throwable =>
|
||||
onError(s"unreadable data=${data.toHex}")
|
||||
throw t
|
||||
}
|
||||
}
|
||||
q
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ class SqliteChannelsDb(sqlite: Connection) extends ChannelsDb with Logging {
|
|||
override def listLocalChannels(): Seq[HasCommitments] = withMetrics("channels/list-local-channels") {
|
||||
using(sqlite.createStatement) { statement =>
|
||||
val rs = statement.executeQuery("SELECT data FROM local_channels WHERE is_closed=0")
|
||||
codecSequence(rs, stateDataCodec)
|
||||
codecSequence(rs, stateDataCodec, onError = { message => logger.error(message) })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue