From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id aE1YMw8Q8WPXIwAAbAwnHQ (envelope-from ) for ; Sat, 18 Feb 2023 18:51:11 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 4Op/Mg8Q8WOIcAEAG6o9tA (envelope-from ) for ; Sat, 18 Feb 2023 18:51:11 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6E85D3B8E0 for ; Sat, 18 Feb 2023 18:51:11 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pTRM6-0005uf-Vr; Sat, 18 Feb 2023 12:50:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTRM5-0005uO-33 for emacs-orgmode@gnu.org; Sat, 18 Feb 2023 12:50:37 -0500 Received: from mail.choca.pics ([2001:910:1410:500::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTRM3-0000Qm-AU for emacs-orgmode@gnu.org; Sat, 18 Feb 2023 12:50:36 -0500 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 1813B18175D27 for ; Sat, 18 Feb 2023 18:50:24 +0100 (CET) Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id atSEc5ZaFwCa for ; Sat, 18 Feb 2023 18:50:23 +0100 (CET) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 74FBA18088E8D for ; Sat, 18 Feb 2023 18:50:23 +0100 (CET) X-Virus-Scanned: amavisd-new at choca.pics Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id 5Gydud8-wyj5 for ; Sat, 18 Feb 2023 18:50:23 +0100 (CET) Received: from localhost (91.60.75.86.rev.sfr.net [86.75.60.91]) by mail.choca.pics (Postfix) with ESMTPSA id 2ECED18088E8C for ; Sat, 18 Feb 2023 18:50:23 +0100 (CET) From: Damien Cassou To: emacs-orgmode@gnu.org Subject: [PATCH] Avoid crash in `org-file-contents' in case of network failure Date: Sat, 18 Feb 2023 18:50:22 +0100 Message-ID: <87cz66278h.fsf@cassou.me> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2001:910:1410:500::1; envelope-from=damien@cassou.me; helo=mail.choca.pics X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1676742671; a=rsa-sha256; cv=none; b=YovWxwGXlm6FfVOiR7mAq5zFyV+RtcR4iwvvPiFclcBuFCREl58wxpfQFi/6jGAyttij8j UqgG5WEc5GPsWFit9jTeFd3zxZfKuWGhcRDtDDRls5QYO/uWkSzDIwL4C8CfqtoLy4NlBM hWJduZkTqaz8AIEvyugDICBIRinHXUIxgO73c2Gl/g6W1BtzmHuUJXOY9Yd23qdp3eL63I CfT14lEo4Bl+WSQkqXaYcHX2c+gimQpdqhhsw4Zzisrbk8TblBoQygwx0JEobxRtV9VwmZ W+PNSRvi/qwqItn5mfyH94jDhAP8pCJpHNejWEsefY8Y29UgVIvzR1VfEck4xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1676742671; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=ylg0n1+wRe7MiMKmhV+4dx9Bk7TX2o/q14nS/3wdQPM=; b=UgTnIgk0gvol2+iojT54qhcl12AQfVkMFIoSosh1xoeyhSL/qu0eFwjnlPFBQrkw1X8BiM TWG9Q2DAUx73e56hFmLqKKTYn/joeMnONTHb1yrOU1rOzAjw9bAU4PTihXPjgWDyrwSJF5 lYD3vO9ibJy2sXwFpCfDTeAs2SHp2LNsUswWqaWHmE4gP8nHQ64qcOOiiAi6hgnWD8hC+W 4QHRJcR5EgxnlJDZt9m+fqqvOmVc1xVK2Lts6zKD4pLVUgdUfcQbjl0ItputkUz6+WnoEe 0IgMa0fFH63oh9eeqlwWAW8rxuE09nVL/wuTmODR5mpKAFfByQqq+KL08dEaDA== X-Migadu-Spam-Score: -2.93 X-Migadu-Scanner: scn1.migadu.com X-Migadu-Queue-Id: 6E85D3B8E0 Authentication-Results: aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none X-Spam-Score: -2.93 X-TUID: 1RK0RWstcXqd --=-=-= Content-Type: text/plain Content-Disposition: inline * 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. -- Damien Cassou "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Avoid-crash-in-org-file-contents-in-case-of-network-.patch >From b13b58711405afd1a065c371251ec0ada35d86dc Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Sat, 18 Feb 2023 12:16:48 +0100 Subject: [PATCH] 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. --- lisp/org.el | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index cc2c09e3a..e777f21f8 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -4561,21 +4561,25 @@ (defun org-file-contents (file &optional noerror nocache) (cache) (is-url (if (org--should-fetch-remote-resource-p file) - (with-current-buffer (url-retrieve-synchronously file) - (goto-char (point-min)) - ;; Move point to after the url-retrieve header. - (search-forward "\n\n" nil :move) - ;; Search for the success code only in the url-retrieve header. - (if (save-excursion - (re-search-backward "HTTP.*\\s-+200\\s-OK" nil :noerror)) - ;; Update the cache `org--file-cache' and return contents. - (puthash file - (buffer-substring-no-properties (point) (point-max)) - org--file-cache) - (funcall (if noerror #'message #'user-error) - "Unable to fetch file from %S" - file) - nil)) + (condition-case error + (with-current-buffer (url-retrieve-synchronously file) + (goto-char (point-min)) + ;; Move point to after the url-retrieve header. + (search-forward "\n\n" nil :move) + ;; Search for the success code only in the url-retrieve header. + (if (save-excursion + (re-search-backward "HTTP.*\\s-+200\\s-OK" nil :noerror)) + ;; Update the cache `org--file-cache' and return contents. + (puthash file + (buffer-substring-no-properties (point) (point-max)) + org--file-cache) + (funcall (if noerror #'message #'user-error) + "Unable to fetch file from %S" + file) + nil)) + (error (if noerror + (message "%s %S" (car error) (cdr error)) + (signal (car error) (cdr error))))) (funcall (if noerror #'message #'user-error) "The remote resource %S is considered unsafe, and will not be downloaded." file))) -- 2.38.3 --=-=-=--