Skip to content

Commit e3598b0

Browse files
committed
Log exceptions in NativeTransport
1 parent d70a392 commit e3598b0

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

libpkl/src/main/java/org/pkl/libpkl/NativeTransport.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,44 @@
3030

3131
public class NativeTransport extends AbstractMessageTransport {
3232
private final BiConsumer<byte[], Object> sendMessageToNative;
33+
private final Logger logger;
3334

3435
protected NativeTransport(Logger logger, BiConsumer<byte[], Object> sendMessageToNative) {
3536
super(logger);
37+
this.logger = logger;
3638
this.sendMessageToNative = sendMessageToNative;
3739
}
3840

3941
@Override
40-
protected void doStart() throws ProtocolException, IOException {}
42+
protected void doStart() {}
4143

4244
@Override
4345
protected void doClose() {}
4446

4547
@Override
46-
protected void doSend(Message message) throws IOException, ProtocolException {
48+
protected void doSend(Message message) {
4749
try (var os = new ByteArrayOutputStream();
4850
var packer = MessagePack.newDefaultPacker(os)) {
4951
var encoder = new ServerMessagePackEncoder(packer);
5052
encoder.encode(message);
5153
// TODO: Propagate `handlerContext` through to `sendMessageToNative`
5254
sendMessageToNative.accept(os.toByteArray(), null);
55+
} catch (IOException | ProtocolException e) {
56+
// TODO: Test that this error message is visible.
57+
logger.log(e.getMessage());
5358
}
5459
}
5560

5661
// TODO: Propagate `handlerContext` through to `sendMessageToNative`
57-
public void sendMessage(int length, CCharPointer ptr, VoidPointer handlerContext)
58-
throws IOException, ProtocolException {
62+
public void sendMessage(int length, CCharPointer ptr, VoidPointer handlerContext) {
5963
try (var is = new NativeInputStream(length, ptr);
6064
var unpacker = MessagePack.newDefaultUnpacker(is)) {
6165
var message = new ServerMessagePackDecoder(unpacker).decode();
6266
assert message != null;
6367
accept(message);
68+
} catch (IOException | ProtocolException e) {
69+
// TODO: Test that this error message is visible.
70+
logger.log(e.getMessage());
6471
}
6572
}
6673
}

0 commit comments

Comments
 (0)