all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Basil L. Contovounesios" via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 58720@debbugs.gnu.org
Cc: Thomas Fitzsimmons <fitzsim@fitzsim.org>
Subject: bug#58720: 29.0.50; Improve error reporting of EUDC plist functions
Date: Sat, 22 Oct 2022 20:39:46 +0300	[thread overview]
Message-ID: <8735bfpxjx.fsf@tcd.ie> (raw)

[-- Attachment #1: Type: text/plain, Size: 632 bytes --]

Severity: wishlist
Tags: patch

In https://bugs.gnu.org/58531#19 it was suggested that
eudc-plist-member, eudc-plist-get, and eudc-lax-plist-get could signal a
more informative wrong-type-argument instead of a generic static error
when passed a degenerate plist argument.  The attached patch makes this
so.

An alternative is to simply call plist-member and plist-get directly,
relying on them for any error reporting, and not worry about arguments
that degenerate further down the list than the point of interest.

WDYT?  How important is it to name and shame degenerate plists as
eagerly as possible in EUDC?

Thanks,

-- 
Basil


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Improve-error-reporting-of-EUDC-plist-functions.patch --]
[-- Type: text/x-diff, Size: 3919 bytes --]

From e9e447214b2b0d19af8b7dc43abbcd4c7944a065 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Sat, 22 Oct 2022 20:25:54 +0300
Subject: [PATCH] Improve error reporting of EUDC plist functions

* lisp/net/eudc.el (eudc--plist-member): Signal a more informative
wrong-type-argument instead of a generic error (bug#58531#19).
* test/lisp/net/eudc-tests.el (eudc--plist-member)
(eudc-plist-member, eudc-plist-get, eudc-lax-plist-get): Update
tests accordingly.
---
 lisp/net/eudc.el            |  5 ++---
 test/lisp/net/eudc-tests.el | 24 ++++++++++++------------
 2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/lisp/net/eudc.el b/lisp/net/eudc.el
index 0283b04574..5f9e78fc7f 100644
--- a/lisp/net/eudc.el
+++ b/lisp/net/eudc.el
@@ -108,9 +108,8 @@ eudc--using-bbdb-3-or-newer-p
 
 (defun eudc--plist-member (plist prop &optional predicate)
   "Like `plist-member', but signal on invalid PLIST."
-  ;; Could also use `plistp', but that would change the error.
-  (or (zerop (% (length plist) 2))
-      (error "Malformed plist"))
+  (or (plistp plist)
+      (signal 'wrong-type-argument `(plistp ,plist)))
   (plist-member plist prop predicate))
 
 (defun eudc-plist-member (plist prop)
diff --git a/test/lisp/net/eudc-tests.el b/test/lisp/net/eudc-tests.el
index 219c250bf0..915006a97c 100644
--- a/test/lisp/net/eudc-tests.el
+++ b/test/lisp/net/eudc-tests.el
@@ -26,9 +26,9 @@ eudc--plist-member
   (dolist (obj '(a (a . a) (a a . a)))
     (should-error (eudc--plist-member obj nil) :type 'wrong-type-argument))
   (dolist (plist '((nil) (a) (a a a)))
-    (dolist (key '(nil a))
-      (should (equal (should-error (eudc--plist-member plist key))
-                     '(error "Malformed plist")))))
+    (let ((err `(wrong-type-argument plistp ,(copy-sequence plist))))
+      (dolist (key '(nil a))
+        (should (equal err (should-error (eudc--plist-member plist key)))))))
   (let ((-nil (string ?n ?i ?l))
         (-a (string ?a)))
     (should-not (eudc--plist-member () nil))
@@ -56,9 +56,9 @@ eudc-plist-member
   (dolist (obj '(a (a . a) (a a . a)))
     (should-error (eudc-plist-member obj nil) :type 'wrong-type-argument))
   (dolist (plist '((nil) (a) (a a a)))
-    (dolist (key '(nil a))
-      (should (equal (should-error (eudc-plist-member plist key))
-                     '(error "Malformed plist")))))
+    (let ((err `(wrong-type-argument plistp ,(copy-sequence plist))))
+      (dolist (key '(nil a))
+        (should (equal err (should-error (eudc-plist-member plist key)))))))
   (let ((-nil (string ?n ?i ?l))
         (-a (string ?a)))
     (should-not (eudc-plist-member () nil))
@@ -86,9 +86,9 @@ eudc-plist-get
   (dolist (obj '(a (a . a) (a a . a)))
     (should-error (eudc-plist-get obj nil) :type 'wrong-type-argument))
   (dolist (plist '((nil) (a) (a a a)))
-    (dolist (key '(nil a))
-      (should (equal (should-error (eudc-plist-get plist key))
-                     '(error "Malformed plist")))))
+    (let ((err `(wrong-type-argument plistp ,(copy-sequence plist))))
+      (dolist (key '(nil a))
+        (should (equal err (should-error (eudc-plist-get plist key)))))))
   (let ((-nil (string ?n ?i ?l))
         (-a (string ?a)))
     (should-not (eudc-plist-get () nil))
@@ -120,9 +120,9 @@ eudc-lax-plist-get
   (dolist (obj '(a (a . a) (a a . a)))
     (should-error (eudc-lax-plist-get obj nil) :type 'wrong-type-argument))
   (dolist (plist '((nil) (a) (a a a)))
-    (dolist (key '(nil a))
-      (should (equal (should-error (eudc-lax-plist-get plist key))
-                     '(error "Malformed plist")))))
+    (let ((err `(wrong-type-argument plistp ,(copy-sequence plist))))
+      (dolist (key '(nil a))
+        (should (equal err (should-error (eudc-lax-plist-get plist key)))))))
   (let ((-nil (string ?n ?i ?l))
         (-a (string ?a)))
     (should-not (eudc-lax-plist-get () nil))
-- 
2.35.1


             reply	other threads:[~2022-10-22 17:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-22 17:39 Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-10-22 18:06 ` bug#58720: 29.0.50; Improve error reporting of EUDC plist functions Thomas Fitzsimmons
2022-10-22 21:51   ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8735bfpxjx.fsf@tcd.ie \
    --to=bug-gnu-emacs@gnu.org \
    --cc=58720@debbugs.gnu.org \
    --cc=contovob@tcd.ie \
    --cc=fitzsim@fitzsim.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.