From: NeilBrown Date: Wed, 28 Jun 2023 21:00:45 +0000 (+1000) Subject: lib-glibevents: catch errors from callbacks. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=929919da2f23ebab932c80b115ecfcc2ee59a916;p=edlib.git lib-glibevents: catch errors from callbacks. The on-idle and poll callbacks didn't catch errors, would cause be fatal. Also change on-idle callbacks to not return errors, on Efalse. Signed-off-by: NeilBrown --- diff --git a/lib-autosave.c b/lib-autosave.c index bdf0132b..eaef0a9e 100644 --- a/lib-autosave.c +++ b/lib-autosave.c @@ -196,11 +196,11 @@ DEF_CMD(ask_autosave) call_comm("editor:notify:all-displays", p, &cr.c); if (!cr.p) /* No display!!! */ - return Efail; + return Efalse; p2 = call_ret(pane, "PopupTile", pane_leaf(cr.p), 0, NULL, "DM3sta"); if (!p2) - return Efail; + return Efalse; if ((s = pane_attr_get(p, "autosave-exists")) != NULL && strcmp(s, "yes") == 0) { @@ -216,7 +216,7 @@ DEF_CMD(ask_autosave) if (!a || !f) { call("popup:close", p2); - return Efail; + return Efalse; } doc = call_ret(pane, "doc:from-text", p, 0, NULL, "*Autosave-Diff*", diff --git a/python/lib-autospell.py b/python/lib-autospell.py index 4d7dce16..6161862e 100644 --- a/python/lib-autospell.py +++ b/python/lib-autospell.py @@ -273,7 +273,7 @@ class autospell_view(edlib.Pane): self.call("doc:notify:spell:choose-range", start, end) if start >= end: # nothing to do - return edlib.Efail + return edlib.Efalse self.set_time() focus = focus.leaf @@ -304,7 +304,7 @@ class autospell_view(edlib.Pane): remain = -1 if remain >= 0: self.sched() - return edlib.Efail + return edlib.Efalse def autospell_attach(key, focus, comm2, **a): p = autospell_view(focus) diff --git a/python/lib-glibevents.py b/python/lib-glibevents.py index 3c31107e..03e47f7e 100644 --- a/python/lib-glibevents.py +++ b/python/lib-glibevents.py @@ -132,7 +132,11 @@ class events(edlib.Pane): while self.idle_list[prio]: s = self.idle_list[prio].pop() f,c,e,n = self.events[s] - if c("callback:on-idle", f, n) > 0: + try: + ret = c("callback:on-idle", f, n) + except edlib.commandfailed: + ret = edlib.Efalse + if ret > 0: if just_one: return @@ -142,7 +146,11 @@ class events(edlib.Pane): self.dont_block = False for s in self.poll_list: f,c,e,n = self.events[s] - if c("callback:poll", f, n) > 0: + try: + ret = c("callback:poll", f, n) + except edlib.commandfailed: + ret = edlib.Efalse + if ret > 0: dont_block = True if not dont_block: # Disable any alarm set by python (or other interpreter)