(error-data): Delete function

Remove `error-data` from the new error API: it is not really
compatible with a more abstract view of error descriptors, and
in practice it seems to be used only in two ways (both of them rare):

- To add some contextual info to an error.  We should maybe add
  a dedicated support for that, but it's not clear what shape it
  should take, ideally (there was a discussion about with Alan
  and myself in emacs-devel a few years ago).
- To do some other massaging whose correctness is dubious anyway.

* doc/lispref/control.texi (Handling Errors): Remove `error-data`.

* lisp/epa-file.el (epa-file--find-file-not-found-function): Don't use
`error-data`.
(epa-file--error-add-context): New function, extracted from
`epa-file-insert-file-contents`.
(epa-file-insert-file-contents): Use it instead of `error-data`.

* lisp/subr.el (error-data): Delete function.
This commit is contained in:
Stefan Monnier
2026-03-10 10:31:14 -04:00
parent 6d8b3d1077
commit fa6f2cb63c
3 changed files with 13 additions and 13 deletions

View File

@@ -2483,10 +2483,6 @@ to @code{condition-case} whose error condition you want to re-throw.
This function returns the error symbol of the error descriptor @var{error}.
@end defun
@defun error-data error
This function returns the data of the error descriptor @var{error}.
@end defun
@defun error-slot-value error pos
This function returns the value in the field number @var{pos} of the error
descriptor @var{error}. The fields are numbered starting with 1. E.g.,

View File

@@ -116,11 +116,15 @@ encryption is used."
(defun epa-file--find-file-not-found-function ()
(let ((error epa-file-error))
(save-window-excursion
(kill-buffer))
(kill-buffer))
;; FIXME: How do we know that slot 3 can hold only a message related
;; to a wrong passphrase?
(if (error-slot-value error 3)
(user-error "Wrong passphrase: %s" (error-slot-value error 3))
;; FIXME: Why does it make sense to add the data fields of ERROR,
;; shifted by one position?
(signal 'file-missing
(cons "Opening input file" (error-data error))))))
(cons "Opening input file" (cdr error))))))
(defun epa--wrong-password-p (context)
"Return whether a wrong password caused the error in CONTEXT."
@@ -136,6 +140,9 @@ encryption is used."
error-string)
(match-string 1 error-string))))
(defun epa-file--error-add-context (err ctxt)
(setf (cdr error) (append (cdr error) (list ctx))))
(defvar last-coding-system-used)
(defun epa-file-insert-file-contents (file &optional visit beg end replace)
(barf-if-buffer-read-only)
@@ -182,8 +189,7 @@ encryption is used."
;; Don't display the *error* buffer if we just
;; have a wrong password; let the later error
;; handler notify the user.
(setf (error-data error)
(append (error-data error) (list wrong-password)))
(epa-file--error-add-context error wrong-password)
(epa-display-error context))
;; When the .gpg file isn't an encrypted file (e.g.,
;; it's a keyring.gpg file instead), then gpg will
@@ -201,8 +207,10 @@ encryption is used."
(add-hook 'find-file-not-found-functions
#'epa-file--find-file-not-found-function
nil t)))
;; FIXME: Why does it make sense to add the data fields
;; of ERROR, shifted by one position?
(signal (if exists 'file-error 'file-missing)
(cons "Opening input file" (error-data error))))))
(cons "Opening input file" (cdr error))))))
(set-buffer buf) ;In case timer/filter changed/killed it (bug#16029)!
(setq-local epa-file-encrypt-to
(mapcar #'car (epg-context-result-for

View File

@@ -586,10 +586,6 @@ Defaults to `error'."
"Return the symbol which represents the type of ERROR.
\n(fn ERROR)")
(defalias 'error-data #'cdr
"Return the slots attached to ERROR, as a list.
\n(fn ERROR)")
(defun error-has-type-p (error condition)
"Return non-nil if ERROR is of type CONDITION (or a subtype of it)."
(unless (error--p error)