Log errors when closing watchers.
authorFredrik Tolf <fredrik@dolda2000.com>
Wed, 16 Feb 2022 18:25:11 +0000 (19:25 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Wed, 16 Feb 2022 18:25:11 +0000 (19:25 +0100)
src/jagi/event/Driver.java

index a8475b4..4d23c76 100644 (file)
@@ -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();
        }