From: Basil L. Contovounesios Date: Sat, 22 Oct 2022 17:25:54 +0000 (+0300) Subject: Improve error reporting of EUDC plist functions X-Git-Tag: emacs-29.0.90~1616^2~497 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9db7b11cf7fa5d6cf624a467f966a14b347e4429;p=emacs.git 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, bug#58720). * test/lisp/net/eudc-tests.el (eudc--plist-member) (eudc-plist-member, eudc-plist-get, eudc-lax-plist-get): Update tests accordingly. --- diff --git a/lisp/net/eudc.el b/lisp/net/eudc.el index 0283b045745..5f9e78fc7f3 100644 --- a/lisp/net/eudc.el +++ b/lisp/net/eudc.el @@ -108,9 +108,8 @@ (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 219c250bf0c..915006a97c1 100644 --- a/test/lisp/net/eudc-tests.el +++ b/test/lisp/net/eudc-tests.el @@ -26,9 +26,9 @@ (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 @@ (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 @@ (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 @@ (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))