From d99e7bfc9d558f263407cc108a1be4bb89f00ed3 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Fri, 25 Mar 2022 12:17:00 -0500 Subject: [PATCH] Fix detekt's SwallowedException warnings --- detekt/baseline.xml | 2 -- src/main/kotlin/io/libp2p/core/multiformats/MultiaddrDns.kt | 3 +++ src/main/kotlin/io/libp2p/etc/types/AsyncExt.kt | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/detekt/baseline.xml b/detekt/baseline.xml index 771f4baf1..ac41f63d7 100644 --- a/detekt/baseline.xml +++ b/detekt/baseline.xml @@ -14,7 +14,5 @@ EqualsWithHashCodeExist:Rsa.kt$RsaPublicKey : PubKey EqualsWithHashCodeExist:Secp256k1.kt$Secp256k1PrivateKey : PrivKey EqualsWithHashCodeExist:Secp256k1.kt$Secp256k1PublicKey : PubKey - SwallowedException:AsyncExt.kt$t: Exception - SwallowedException:MultiaddrDns.kt$MultiaddrDns.Companion$e: UnknownHostException diff --git a/src/main/kotlin/io/libp2p/core/multiformats/MultiaddrDns.kt b/src/main/kotlin/io/libp2p/core/multiformats/MultiaddrDns.kt index 6672499e0..61e0fcd4a 100644 --- a/src/main/kotlin/io/libp2p/core/multiformats/MultiaddrDns.kt +++ b/src/main/kotlin/io/libp2p/core/multiformats/MultiaddrDns.kt @@ -1,5 +1,6 @@ package io.libp2p.core.multiformats +import org.apache.logging.log4j.LogManager import java.net.Inet4Address import java.net.Inet6Address import java.net.InetAddress @@ -12,6 +13,7 @@ class MultiaddrDns { } companion object { + private val log = LogManager.getLogger(MultiaddrDns::class.java) private val dnsProtocols = arrayOf(Protocol.DNS4, Protocol.DNS6, Protocol.DNSADDR) fun resolve(addr: Multiaddr, resolver: Resolver = DefaultResolver): List { @@ -52,6 +54,7 @@ class MultiaddrDns { } } } catch (e: UnknownHostException) { + log.debug(e) return emptyList() // squash, as this might not be fatal, // and if it is we'll handle this higher up the call chain diff --git a/src/main/kotlin/io/libp2p/etc/types/AsyncExt.kt b/src/main/kotlin/io/libp2p/etc/types/AsyncExt.kt index 6d607c141..0e24eb4d4 100644 --- a/src/main/kotlin/io/libp2p/etc/types/AsyncExt.kt +++ b/src/main/kotlin/io/libp2p/etc/types/AsyncExt.kt @@ -22,6 +22,7 @@ fun CompletableFuture.forward(forwardTo: CompletableFuture) = forwa /** * The same as [CompletableFuture.get] but unwraps [ExecutionException] */ +@Suppress("SwallowedException") fun CompletableFuture.getX(): C { try { return get() @@ -36,6 +37,7 @@ fun CompletableFuture.getX(): C { /** * The same as [CompletableFuture.get] but unwraps [ExecutionException] */ +@Suppress("SwallowedException") fun CompletableFuture.getX(timeoutSec: Double): C { try { return get((timeoutSec * 1000).toLong(), TimeUnit.MILLISECONDS)