From da4f1fa550f753e76c611b313d4f00987daed5ad Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 4 Mar 2023 14:53:01 -0700 Subject: [PATCH] server-eval-at: Signal more specific condition on unreadable result * lisp/server.el (server-return-invalid-read-syntax): New error signal. (server-eval-at): Re-signal invalid-read-syntax as server-return-invalid-read-syntax (bug#61658). --- lisp/server.el | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index 35b38ef8fa6..89aedc72d52 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -1929,12 +1929,22 @@ This sets the variable `server-stop-automatically' (which see)." ;; continue standard unloading nil) +(define-error 'server-return-invalid-read-syntax + "Emacs server returned unreadable result of evaluation" + 'invalid-read-syntax) + (defun server-eval-at (server form) "Contact the Emacs server named SERVER and evaluate FORM there. -Returns the result of the evaluation, or signals an error if it -cannot contact the specified server. For example: +Returns the result of the evaluation. For example: (server-eval-at \"server\" \\='(emacs-pid)) -returns the process ID of the Emacs instance running \"server\"." +returns the process ID of the Emacs instance running \"server\". + +This function signals `error' if it could not contact the server. + +This function signals `server-return-invalid-read-syntax' if it +couldn't read the result of evaluation printed by the server. +This will occur whenever the result of evaluating FORM is something +not readably printable." (let* ((server-dir (if server-use-tcp server-auth-dir server-socket-dir)) (server-file (expand-file-name server server-dir)) (coding-system-for-read 'binary) @@ -1980,8 +1990,14 @@ returns the process ID of the Emacs instance running \"server\"." (progn (skip-chars-forward "^\n") (point)))))) (if (not (equal answer "")) - (read (decode-coding-string (server-unquote-arg answer) - 'emacs-internal))))))) + (condition-case err + (read + (decode-coding-string (server-unquote-arg answer) + 'emacs-internal)) + ;; Re-signal with a more specific condition. + (invalid-read-syntax + (signal 'server-return-invalid-read-syntax + (cdr err))))))))) (provide 'server) -- 2.39.2