mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-08-24 22:02:52 +00:00
org.el: Avoid crash in `org-file-contents' in case of network failure
* lisp/org.el (org-file-contents): Wrap the `url-retrieve-synchronously' call into a `condition-case' block to avoid throwing an error when NOERROR is non-nil. TINYCHANGE
This commit is contained in:
parent
7a90f596d9
commit
f9aeba5dd7
34
lisp/org.el
34
lisp/org.el
|
@ -4559,21 +4559,25 @@ is available. This option applies only if FILE is a URL."
|
||||||
(cache)
|
(cache)
|
||||||
(is-url
|
(is-url
|
||||||
(if (org--should-fetch-remote-resource-p file)
|
(if (org--should-fetch-remote-resource-p file)
|
||||||
(with-current-buffer (url-retrieve-synchronously file)
|
(condition-case error
|
||||||
(goto-char (point-min))
|
(with-current-buffer (url-retrieve-synchronously file)
|
||||||
;; Move point to after the url-retrieve header.
|
(goto-char (point-min))
|
||||||
(search-forward "\n\n" nil :move)
|
;; Move point to after the url-retrieve header.
|
||||||
;; Search for the success code only in the url-retrieve header.
|
(search-forward "\n\n" nil :move)
|
||||||
(if (save-excursion
|
;; Search for the success code only in the url-retrieve header.
|
||||||
(re-search-backward "HTTP.*\\s-+200\\s-OK" nil :noerror))
|
(if (save-excursion
|
||||||
;; Update the cache `org--file-cache' and return contents.
|
(re-search-backward "HTTP.*\\s-+200\\s-OK" nil :noerror))
|
||||||
(puthash file
|
;; Update the cache `org--file-cache' and return contents.
|
||||||
(buffer-substring-no-properties (point) (point-max))
|
(puthash file
|
||||||
org--file-cache)
|
(buffer-substring-no-properties (point) (point-max))
|
||||||
(funcall (if noerror #'message #'user-error)
|
org--file-cache)
|
||||||
"Unable to fetch file from %S"
|
(funcall (if noerror #'message #'user-error)
|
||||||
file)
|
"Unable to fetch file from %S"
|
||||||
nil))
|
file)
|
||||||
|
nil))
|
||||||
|
(error (if noerror
|
||||||
|
(message "Org could't download \"%s\": %s %S" file (car error) (cdr error))
|
||||||
|
(signal (car error) (cdr error)))))
|
||||||
(funcall (if noerror #'message #'user-error)
|
(funcall (if noerror #'message #'user-error)
|
||||||
"The remote resource %S is considered unsafe, and will not be downloaded."
|
"The remote resource %S is considered unsafe, and will not be downloaded."
|
||||||
file)))
|
file)))
|
||||||
|
|
Loading…
Reference in a new issue