Subject: bug#43401: 28.0.50; [PATCH] Emacs Lisp type error when the buffer passed to diff-buffer-with-file is not visiting a file

From: Daniel Martín <[email-masked]>
Date: Mon, 14 Sep 2020 18:12:11 +0200

Steps to reproduce the problem:

emacs -Q
C-x b "Sample" RET (that is, create an empty buffer)
M-x diff-buffer-with-file RET
RET (confirm the default buffer)

Actual result:

Emacs shows "Wrong type argument: stringp, nil"

Expected result:

Emacs shows a more descriptive error that explains why the command
couldn't be executed.

I've attached a patch that implements the expected result.

Thank you very much.

>From 5fdeef8b44a4742ef9f745981e3c202a43697085 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <[email-masked]>
Date: Mon, 14 Sep 2020 17:58:58 +0200
Subject: [PATCH] Check that the buffer in diff-buffer-with-file is visiting a
 file

* lisp/vc/diff.el (diff-buffer-with-file): Signal a specific error
when the buffer passed to diff-buffer-with-file is not visiting a
file.
---
 lisp/vc/diff.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lisp/vc/diff.el b/lisp/vc/diff.el
index 469888078c..b7f17bf3c7 100644
--- a/lisp/vc/diff.el
+++ b/lisp/vc/diff.el
@@ -258,6 +258,8 @@ diff-buffer-with-file
   (interactive "bBuffer: ")
   (let ((buf (get-buffer (or buffer (current-buffer)))))
     (with-current-buffer (or (buffer-base-buffer buf) buf)
+      (unless buffer-file-name
+        (error "Buffer is not visiting a file"))
       (diff buffer-file-name (current-buffer) nil 'noasync))))
 
 ;;;###autoload
-- 
2.28.0