Subject: bug#58552: 29.0.50; [PATCH] dictionary-lookup-definition "Wrong type argument" error when there is no word at point

From: Daniel Martín <[email-masked]>
Date: Sat, 15 Oct 2022 21:36:35 +0200

Steps to reproduce the issue:

emacs -Q
M-x dictionary-lookup-definition RET
Answer "y" if asked about using dict.org.

Expected result:

As there is no word at point to act on, the operation should inform the
user right away.

Actual result:

dictionary-encode-charset: Wrong type argument: stringp, nil

An empty dictionary buffer is shown, which is confusing.

The attached patch informs the user that there is no word at point to
act on and aborts the operation early.

If you think it's a good patch, please install on my behalf.  Thanks.

>From ac9505d3105138c69b018d6432182e45d12a2bb5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <[email-masked]>
Date: Sat, 15 Oct 2022 21:25:59 +0200
Subject: [PATCH] Signal an error in dictionary lookup if there's no word at
 point

* lisp/net/dictionary.el (dictionary-lookup-definition): Signal an
error when there is no word at point.
---
 lisp/net/dictionary.el | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lisp/net/dictionary.el b/lisp/net/dictionary.el
index 4c52382c67..b8f5018005 100644
--- a/lisp/net/dictionary.el
+++ b/lisp/net/dictionary.el
@@ -1173,7 +1173,10 @@ dictionary-search
 (defun dictionary-lookup-definition ()
   "Unconditionally lookup the word at point."
   (interactive)
-  (dictionary-new-search (cons (current-word) dictionary-default-dictionary)))
+  (let ((word (current-word)))
+    (unless word
+      (error "No word at point"))
+    (dictionary-new-search (cons word dictionary-default-dictionary))))
 
 (defun dictionary-previous ()
   "Go to the previous location in the current buffer."
-- 
2.34.1