From 9e48a95cf29f39b30b03e946cdd05c7664053fd7 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Thu, 6 Nov 2014 12:04:22 +0900 Subject: epg: Improve error handling * epa.el (epa-error-buffer): New variable. (epa-display-error): New function. (epa-decrypt-file, epa-verify-file, epa-verify-region) (epa-delete-keys, epa-import-keys): Display output sent to stderr. (epa-sign-file, epa-sign-region, epa-encrypt-region) (epa-export-keys, epa-insert-keys): Display output sent to stderr. Use setf instead of epg-context-set-*. * epa-file.el (epa-file-insert-file-contents): Use epa-display-error instead of epa-display-info. Mimic the behavior of jka-compr when decryption program is not found. (epa-file-write-region): Use epa-display-error instead of epa-display-info. --- lisp/epa-file.el | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'lisp/epa-file.el') diff --git a/lisp/epa-file.el b/lisp/epa-file.el index 6f3bb188190..759271bc4e8 100644 --- a/lisp/epa-file.el +++ b/lisp/epa-file.el @@ -105,9 +105,9 @@ encryption is used." (insert (if enable-multibyte-characters (string-to-multibyte string) string)) - (decode-coding-inserted-region - (point-min) (point-max) - (substring file 0 (string-match epa-file-name-regexp file)) + (decode-coding-inserted-region + (point-min) (point-max) + (substring file 0 (string-match epa-file-name-regexp file)) visit beg end replace)) (insert (epa-file--decode-coding-string string (or coding-system-for-read 'undecided))))) @@ -151,8 +151,17 @@ encryption is used." (condition-case error (setq string (epg-decrypt-file context local-file nil)) (error + (epa-display-error context) (if (setq entry (assoc file epa-file-passphrase-alist)) (setcdr entry nil)) + ;; If the decryption program can't be found, + ;; signal that as a non-file error + ;; so that find-file-noselect-1 won't handle it. + ;; Borrowed from jka-compr.el. + (if (and (eq (car error) 'file-error) + (equal (cadr error) "Searching for program")) + (error "Decryption program `%s' not found" + (nth 3 error))) ;; Hack to prevent find-file from opening empty buffer ;; when decryption failed (bug#6568). See the place ;; where `find-file-not-found-functions' are called in @@ -162,11 +171,6 @@ encryption is used." (add-hook 'find-file-not-found-functions 'epa-file--find-file-not-found-function nil t)) - (if (epg-context-error-output context) - (epa-display-info - (concat (format "Error while executing \"%s\":\n\n" - epg-gpg-program) - (epg-context-error-output context)))) (signal 'file-error (cons "Opening input file" (cdr error))))) (set-buffer buf) ;In case timer/filter changed/killed it (bug#16029)! @@ -226,7 +230,7 @@ encryption is used." context (cons #'epa-progress-callback-function (format "Encrypting %s" file))) - (epg-context-set-armor context epa-armor) + (setf (epg-context-armor context) epa-armor) (condition-case error (setq string (epg-encrypt-string @@ -260,13 +264,9 @@ If no one is selected, symmetric encryption will be performed. " (if epa-file-encrypt-to (epg-list-keys context recipients))))) (error + (epa-display-error context) (if (setq entry (assoc file epa-file-passphrase-alist)) (setcdr entry nil)) - (if (epg-context-error-output context) - (epa-display-info - (concat (format "Error while executing \"%s\":\n\n" - epg-gpg-program) - (epg-context-error-output context)))) (signal 'file-error (cons "Opening output file" (cdr error))))) (epa-file-run-real-handler #'write-region -- cgit v1.2.3