From 7a3bde5c801b293fae82e4e24b740164d9659c74 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Wed, 16 Feb 2022 19:25:11 +0100 Subject: [PATCH] Log errors when closing watchers. --- src/jagi/event/Driver.java | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/jagi/event/Driver.java b/src/jagi/event/Driver.java index a8475b4..4d23c76 100644 --- a/src/jagi/event/Driver.java +++ b/src/jagi/event/Driver.java @@ -26,7 +26,18 @@ public class Driver { current.set(this); w.handle(evs); } catch(Throwable t) { - error(w, t); + error(w, t, "handling event"); + } finally { + current.remove(); + } + } + + protected void close(Watcher w) { + try { + current.set(this); + w.close(); + } catch(Throwable t) { + error(w, t, "closing"); } finally { current.remove(); } @@ -36,8 +47,8 @@ public class Driver { worker.submit(task); } - protected void error(Watcher w, Throwable t) { - hlog.log(Level.WARNING, w + ": uncaught error when handling event", t); + protected void error(Watcher w, Throwable t, String thing) { + hlog.log(Level.WARNING, w + ": uncaught error when " + thing, t); remove(w); } @@ -164,7 +175,7 @@ public class Driver { double timeout = w.timeout(); boolean hastime = timeout < Double.POSITIVE_INFINITY; if(evs < 0) { - submit(w::close); + submit(() -> close(w)); return; } w.added(Driver.this); @@ -188,7 +199,7 @@ public class Driver { throw(new RuntimeException(w + ": inconsistent internal state")); if(wc == null) throw(new IllegalStateException(w + ": not registered")); - submit(w::close); + submit(() -> close(w)); poll.wakeup(); } -- 2.11.0