]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix (find-file "/dev/null")
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 11 Jul 2025 22:33:26 +0000 (15:33 -0700)
committerEshel Yaron <me@eshelyaron.com>
Thu, 24 Jul 2025 08:47:26 +0000 (10:47 +0200)
* lisp/files.el (find-file-noselect-1): When the file exists,
propagate any errors signaled by insert-file-contents,
instead of propagating them only when the file is unreadable.
This way, (find-file "/dev/null") gives a sensible diagnostic
"not a regular file" instead of the nonsense
"Maximum buffer size exceeded".

(cherry picked from commit b911029f96b14a03398198d5a849d6f4d0d1e071)

lisp/files.el

index b335d8d9651c6242de1d98523e09e96c7ebe6835..3885637ed5896ddb12764673785b2da277b72bcb 100644 (file)
@@ -2671,27 +2671,29 @@ Do you want to revisit the file normally now? "))
       (and (not rawfile)
           (set-buffer-multibyte t))
       (if rawfile
-         (condition-case ()
+         (condition-case err
              (let ((inhibit-read-only t)
                     (enable-local-variables nil))
                (insert-file-contents-literally filename t))
            (file-error
-            (when (and (file-exists-p filename)
-                       (not (file-readable-p filename)))
+            (when (file-exists-p filename)
               (kill-buffer buf)
-              (signal 'file-error (list "File is not readable"
-                                        filename)))
+              (signal 'file-error
+                      (if (file-readable-p filename)
+                          (cdr err)
+                        (list "File is not readable" filename))))
             ;; Unconditionally set error
             (setq error t)))
-       (condition-case ()
+       (condition-case err
            (let ((inhibit-read-only t))
              (insert-file-contents filename t))
          (file-error
-          (when (and (file-exists-p filename)
-                     (not (file-readable-p filename)))
+          (when (file-exists-p filename)
             (kill-buffer buf)
-            (signal 'file-error (list "File is not readable"
-                                      filename)))
+            (signal 'file-error
+                    (if (file-readable-p filename)
+                        (cdr err)
+                      (list "File is not readable" filename))))
           ;; Run find-file-not-found-functions until one returns non-nil.
           (or (run-hook-with-args-until-success 'find-file-not-found-functions)
               ;; If they fail too, set error.