emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/buttercup 25462dd 223/340: Record calls to spied-on functi


From: ELPA Syncer
Subject: [nongnu] elpa/buttercup 25462dd 223/340: Record calls to spied-on functions that throw errors
Date: Thu, 16 Dec 2021 14:59:39 -0500 (EST)

branch: elpa/buttercup
commit 25462ddfdf430308c5fa9219d2f16a626e2913cf
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>

    Record calls to spied-on functions that throw errors
    
    This addes another slot to the spy-context struct that is used to
    record the signal thrown by the spied function, if any.
    
    Fixes #139.
---
 buttercup.el | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/buttercup.el b/buttercup.el
index ba5c203..fdddc7e 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -1025,6 +1025,7 @@ DESCRIPTION has the same meaning as in `xit'. FUNCTION is 
ignored."
 (cl-defstruct spy-context
   args
   return-value
+  thrown-signal
   current-buffer)
 
 (defun spy-on (symbol &optional keyword arg)
@@ -1106,15 +1107,35 @@ responsibility to ensure ARG is a command."
 (defun buttercup--make-spy (fun)
   "Create a new spy function wrapping FUN and tracking calls to itself."
   (let (this-spy-function)
-    (setq this-spy-function
-          (lambda (&rest args)
-            (let ((return-value (apply fun args)))
+    (setq
+     this-spy-function
+     (lambda (&rest args)
+       (let ((returned nil)
+             (return-value nil))
+         (condition-case err
+             (progn
+               (setq return-value (apply fun args)
+                     returned t)
+               (buttercup--spy-calls-add
+                this-spy-function
+                (make-spy-context :args args
+                                  :return-value return-value
+                                  :thrown-signal nil
+                                  :current-buffer (current-buffer)))
+               return-value)
+           (error
+            ;; If returned is non-nil, then the error we caught
+            ;; didn't come from FUN, so we shouldn't record it.
+            (unless returned
               (buttercup--spy-calls-add
                this-spy-function
                (make-spy-context :args args
-                                 :return-value return-value
-                                 :current-buffer (current-buffer)))
-              return-value)))
+                                 :return-value nil
+                                 :thrown-signal err
+                                 :current-buffer (current-buffer))))
+            ;; Regardless, we only caught this error order to record
+            ;; it, so we need to re-throw it.
+            (signal (car err) (cdr err)))))))
     ;; Add the interactive form from `fun', if any
     (when (interactive-form fun)
       (setq this-spy-function



reply via email to

[Prev in Thread] Current Thread [Next in Thread]