From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id IHNILqqQ+GMRKAEAbAwnHQ (envelope-from ) for ; Fri, 24 Feb 2023 11:25:46 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id OLBSLqqQ+GOqZwEA9RJhRA (envelope-from ) for ; Fri, 24 Feb 2023 11:25:46 +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 643CE14F8A for ; Fri, 24 Feb 2023 11:25:46 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVVGC-0000Q1-LG; Fri, 24 Feb 2023 05:25:04 -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 1pVVG9-0000PB-BF for emacs-orgmode@gnu.org; Fri, 24 Feb 2023 05:25:02 -0500 Received: from mail.choca.pics ([80.67.172.235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pVVG7-0007rd-6h; Fri, 24 Feb 2023 05:25:00 -0500 Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id C1A6D18095ABE; Fri, 24 Feb 2023 11:24:55 +0100 (CET) Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id J4_0Loryz0Gq; Fri, 24 Feb 2023 11:24:55 +0100 (CET) Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 20F4B18095ABC; Fri, 24 Feb 2023 11:24:55 +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 C69C00EdsdLA; Fri, 24 Feb 2023 11:24:54 +0100 (CET) Received: from localhost (91.60.75.86.rev.sfr.net [86.75.60.91]) by mail.choca.pics (Postfix) with ESMTPSA id BE86A18095AB0; Fri, 24 Feb 2023 11:24:54 +0100 (CET) From: Damien Cassou To: Ihor Radchenko , Bastien Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] Avoid crash in `org-file-contents' in case of network failure In-Reply-To: <877cw7s6yx.fsf@localhost> References: <87cz66278h.fsf@cassou.me> <87y1oqcaif.fsf@localhost> <87y1onsfpg.fsf@cassou.me> <877cw7s6yx.fsf@localhost> Date: Fri, 24 Feb 2023 11:24:54 +0100 Message-ID: <87pm9ztl6x.fsf@cassou.me> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=80.67.172.235; 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-Country: US X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1677234346; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=/2qVMtz4AErlXz1uxOWJyPYg1xP4d+bePMwFkXIsdU8=; b=MzOhUkt0gPU3Ku5RPdIY8C2mQWFcRmQxxOrHiEaRnGwCUFIRgRJine4QxQOw9RYsWFolWf IO8G2CdH93/mQLX3An8i4LcrVHXFADvnbVWb8ixQmHZtXOdSPYksc43ZnVfm/i6jpVe0ik 0bMhIsG+lhA8dFw4R2uiywDudeKPkXU9gafDXVAyakMd70btPOCDl23xxfqAiV3b4jNwjo 4mNqHHFdu4JDnwYIh0VuSRnMrCJH6wRgz4euIvTBENWwoToVbImMHVwHjWtttQHciSzRnU /ddXNgSCF1djrkOAMRd7fT+AhlTQEvZT2HUO5YMJg7BkLztDA9ocmLKhbAOJiw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=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" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1677234346; a=rsa-sha256; cv=none; b=JSTJz65rqODMzJxlY0cS5Sa2F8mCgXYYjBSS1JUoD1wQun8e8kegjTImAiAXfl6NFWsgmH 1rokrXVYfNU53HFDr2lB8LxpROmmFYAisc/hyASjUaORguSnjUO9vaE1FdDykj0ciEBGGW f63kt/zOGVJ7Fl0q2tN0gBf9OzcmeFlWpsJqR8RSoQg+Oml3B/ZQCDqZAFMwJPWDHYClP8 rqs+9R96bEsCZj15yTXBPzJutNvQFjuZfqN7uT5N2Kxt6CflBGGAfq1QgAhxXsGVkJRX7R ySwDWiLJZ+jS5wqYROI7H9a2ydijC/X7iCxt76y83BSbrkYjcCNpUVkiR15Xlw== Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=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" X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -2.98 X-Spam-Score: -2.98 X-Migadu-Queue-Id: 643CE14F8A X-TUID: dIenaGh8A6g7 --=-=-= Content-Type: text/plain Ihor Radchenko writes: > I think you forgot to attach the updated patch :) typical. I'm so sorry. -- 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-org.el-Avoid-crash-in-org-file-contents-in-case-of-n.patch >From c116e27a84972f9e12a869f2b4983bb84ee50b15 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Sat, 18 Feb 2023 12:16:48 +0100 Subject: [PATCH] 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 --- lisp/org.el | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index b0a6d8ef3..a9fd76734 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 "Org could't download \"%s\": %s %S" file (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 --=-=-=--