Skip to content

Commit

Permalink
Filter out stack traces when network is unreachable
Browse files Browse the repository at this point in the history
This is a likely condition in my use case, and having an error message
logged is enough. I do not need the complete stack trace.
  • Loading branch information
Jurrie committed Jan 6, 2025
1 parent 7626f4b commit 37aaea5
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.StandardProtocolFamily;
import java.net.StandardSocketOptions;
import java.net.UnixDomainSocketAddress;
Expand Down Expand Up @@ -140,7 +141,7 @@ public List<SocketAddress> getRemotes()
public void send(final OSCPacket packet) throws IOException, OSCSerializeException
{
LOGGER.warn("Sending packet to all known sources, even the source that orignally sent us the message!");
oscChannel.send(sendBuffer, packet, remotes);
send(packet, null);
}

/**
Expand Down Expand Up @@ -326,9 +327,24 @@ public void send(final ByteBuffer sendBuffer, final OSCPacket packet, final List
{
LOGGER.trace("Sending to {}", remoteAddress);
sendBuffer.rewind();
underlyingChannel.send(sendBuffer, remoteAddress);
try
{
underlyingChannel.send(sendBuffer, remoteAddress);
}
catch (SocketException e)
{
final String errorMessage = e.getMessage();
if (errorMessage != null && errorMessage.contains("Network is unreachable"))
{
LOGGER.warn("Could not send to {} because that network was unreachable", remoteAddress);
}
else
{
throw e;
}
}
}
sendBuffer.flip();
sendBuffer.clear();
completed = true;
}
finally
Expand Down

0 comments on commit 37aaea5

Please sign in to comment.