diff options
| author | Stefan Monnier | 2026-03-08 23:28:11 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2026-03-08 23:28:11 -0400 |
| commit | 225977cda7c819c3bbf018d870c0eedfa92023bd (patch) | |
| tree | b81e3e98b3cb651f47ddc96bb926ec62fe0d5fa7 /lisp/epa-file.el | |
| parent | 0349286fb6c4d4b4c67b5ae0e51e8ece196fbfb9 (diff) | |
| download | emacs-feature/error-API.tar.gz emacs-feature/error-API.zip | |
Use the new error API functionsfeature/error-API
* lisp/epa-file.el (epa-file--find-file-not-found-function):
Use `error-slot-value` and `error-data`.
(epa-file-insert-file-contents): Use `error-has-type-p`,
`error-slot-value`, and `error-data`.
* lisp/jka-compr.el (jka-compr-insert-file-contents):
Use `error-has-type-p` and `error-slot-value` as well as new
re-signaling form of `signal`.
* lisp/simple.el (minibuffer-error-function): Use `error-has-type-p`.
* lisp/startup.el (startup--load-user-init-file):
Use `error-message-string`.
(command-line): Use `error-has-type-p` and `error-message-string`.
* lisp/type-break.el (type-break-demo-life):
Use `error-message-string`.
* lisp/emacs-lisp/bytecomp.el (batch-byte-compile-file):
Use `error-message-string` and `error-has-type-p`.
* lisp/emacs-lisp/edebug.el (edebug-safe-eval, edebug-report-error)
(edebug-eval-expression):
* lisp/emacs-lisp/debug.el (debugger-eval-expression):
Use `error-message-string`.
* lisp/emacs-lisp/ert.el (ert--should-error-handle-error):
Use `error-has-type-p` and `error-type`.
* lisp/net/sasl.el (sasl-error): Use `define-error`.
* lisp/net/tramp-compat.el (tramp-error-type-p): New function.
(tramp-permission-denied, tramp-compat-permission-denied): Use it.
* lisp/progmodes/elisp-mode.el (elisp-completion-at-point):
Use `error-type-p`.
Diffstat (limited to 'lisp/epa-file.el')
| -rw-r--r-- | lisp/epa-file.el | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lisp/epa-file.el b/lisp/epa-file.el index 9bf6916ff7a..ced54b6eeed 100644 --- a/lisp/epa-file.el +++ b/lisp/epa-file.el | |||
| @@ -117,10 +117,10 @@ encryption is used." | |||
| 117 | (let ((error epa-file-error)) | 117 | (let ((error epa-file-error)) |
| 118 | (save-window-excursion | 118 | (save-window-excursion |
| 119 | (kill-buffer)) | 119 | (kill-buffer)) |
| 120 | (if (nth 3 error) | 120 | (if (error-slot-value error 3) |
| 121 | (user-error "Wrong passphrase: %s" (nth 3 error)) | 121 | (user-error "Wrong passphrase: %s" (error-slot-value error 3)) |
| 122 | (signal 'file-missing | 122 | (signal 'file-missing |
| 123 | (cons "Opening input file" (cdr error)))))) | 123 | (cons "Opening input file" (error-data error)))))) |
| 124 | 124 | ||
| 125 | (defun epa--wrong-password-p (context) | 125 | (defun epa--wrong-password-p (context) |
| 126 | "Return whether a wrong password caused the error in CONTEXT." | 126 | "Return whether a wrong password caused the error in CONTEXT." |
| @@ -171,23 +171,25 @@ encryption is used." | |||
| 171 | ;; signal that as a non-file error | 171 | ;; signal that as a non-file error |
| 172 | ;; so that find-file-noselect-1 won't handle it. | 172 | ;; so that find-file-noselect-1 won't handle it. |
| 173 | ;; Borrowed from jka-compr.el. | 173 | ;; Borrowed from jka-compr.el. |
| 174 | (if (and (memq 'file-error (get (car error) 'error-conditions)) | 174 | (if (and (error-has-type-p error 'file-error) |
| 175 | (equal (cadr error) "Searching for program")) | 175 | (equal (error-slot-value error 1) |
| 176 | "Searching for program")) | ||
| 176 | (error "Decryption program `%s' not found" | 177 | (error "Decryption program `%s' not found" |
| 177 | (nth 3 error))) | 178 | (error-slot-value error 3))) |
| 178 | (let ((exists (file-exists-p local-file))) | 179 | (let ((exists (file-exists-p local-file))) |
| 179 | (when exists | 180 | (when exists |
| 180 | (if-let* ((wrong-password (epa--wrong-password-p context))) | 181 | (if-let* ((wrong-password (epa--wrong-password-p context))) |
| 181 | ;; Don't display the *error* buffer if we just | 182 | ;; Don't display the *error* buffer if we just |
| 182 | ;; have a wrong password; let the later error | 183 | ;; have a wrong password; let the later error |
| 183 | ;; handler notify the user. | 184 | ;; handler notify the user. |
| 184 | (setq error (append error (list wrong-password))) | 185 | (setf (error-data error) |
| 186 | (append (error-data error) (list wrong-password))) | ||
| 185 | (epa-display-error context)) | 187 | (epa-display-error context)) |
| 186 | ;; When the .gpg file isn't an encrypted file (e.g., | 188 | ;; When the .gpg file isn't an encrypted file (e.g., |
| 187 | ;; it's a keyring.gpg file instead), then gpg will | 189 | ;; it's a keyring.gpg file instead), then gpg will |
| 188 | ;; say "Unexpected exit" as the error message. In | 190 | ;; say "Unexpected exit" as the error message. In |
| 189 | ;; that case, just display the bytes. | 191 | ;; that case, just display the bytes. |
| 190 | (if (equal (caddr error) "Unexpected; Exit") | 192 | (if (equal (error-slot-value error 2) "Unexpected; Exit") |
| 191 | (setq string (with-temp-buffer | 193 | (setq string (with-temp-buffer |
| 192 | (insert-file-contents-literally local-file) | 194 | (insert-file-contents-literally local-file) |
| 193 | (buffer-string))) | 195 | (buffer-string))) |
| @@ -197,10 +199,10 @@ encryption is used." | |||
| 197 | ;; `find-file-noselect-1'. | 199 | ;; `find-file-noselect-1'. |
| 198 | (setq-local epa-file-error error) | 200 | (setq-local epa-file-error error) |
| 199 | (add-hook 'find-file-not-found-functions | 201 | (add-hook 'find-file-not-found-functions |
| 200 | 'epa-file--find-file-not-found-function | 202 | #'epa-file--find-file-not-found-function |
| 201 | nil t))) | 203 | nil t))) |
| 202 | (signal (if exists 'file-error 'file-missing) | 204 | (signal (if exists 'file-error 'file-missing) |
| 203 | (cons "Opening input file" (cdr error)))))) | 205 | (cons "Opening input file" (error-data error)))))) |
| 204 | (set-buffer buf) ;In case timer/filter changed/killed it (bug#16029)! | 206 | (set-buffer buf) ;In case timer/filter changed/killed it (bug#16029)! |
| 205 | (setq-local epa-file-encrypt-to | 207 | (setq-local epa-file-encrypt-to |
| 206 | (mapcar #'car (epg-context-result-for | 208 | (mapcar #'car (epg-context-result-for |