From patchwork Sun Apr 21 09:42:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 63245 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id B56E427BBE2; Sun, 21 Apr 2024 10:44:08 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id BA8E827BBE9 for ; Sun, 21 Apr 2024 10:44:07 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ryTjy-0005WN-ON; Sun, 21 Apr 2024 05:44:06 -0400 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 1ryTjo-0005Sl-8e for guix-patches@gnu.org; Sun, 21 Apr 2024 05:43:56 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ryTjn-0002pv-Vz; Sun, 21 Apr 2024 05:43:56 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ryTk2-0006WM-JJ; Sun, 21 Apr 2024 05:44:10 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70494] [PATCH 18/23] guix: http-client: Add network-error?. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Sun, 21 Apr 2024 09:44:10 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70494 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70494@debbugs.gnu.org Cc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 70494-submit@debbugs.gnu.org id=B70494.171369263624785 (code B ref 70494); Sun, 21 Apr 2024 09:44:10 +0000 Received: (at 70494) by debbugs.gnu.org; 21 Apr 2024 09:43:56 +0000 Received: from localhost ([127.0.0.1]:41791 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ryTjl-0006RL-Vd for submit@debbugs.gnu.org; Sun, 21 Apr 2024 05:43:55 -0400 Received: from mira.cbaines.net ([2a01:7e00:e000:2f8:fd4d:b5c7:13fb:3d27]:46331) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ryTj0-0006IW-0M for 70494@debbugs.gnu.org; Sun, 21 Apr 2024 05:43:09 -0400 Received: from localhost (unknown [IPv6:2a02:6b67:d93b:1:254c:b471:debc:14be]) by mira.cbaines.net (Postfix) with ESMTPSA id 675C627BBF8 for <70494@debbugs.gnu.org>; Sun, 21 Apr 2024 10:42:48 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id d4947319 for <70494@debbugs.gnu.org>; Sun, 21 Apr 2024 09:42:48 +0000 (UTC) From: Christopher Baines Date: Sun, 21 Apr 2024 10:42:36 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: <87bk632h36.fsf@cbaines.net> References: <87bk632h36.fsf@cbaines.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Plus remove http-get-error? from network-error? as a http-get-error? doesn't indicate a network error. * guix/scripts/substitute.scm (system-error?, network-error?): Move from here. (process-substitution/fallback, process-substitution): Use http-get-error? with network-error?. * guix/http-client.scm: To here, and also don't use http-get-error?. Change-Id: I61ee9e5fbf90ebb76a34aa8b9ec8f5d74f8a3c54 --- guix/http-client.scm | 23 +++++++++++++++++++++++ guix/scripts/substitute.scm | 26 ++++---------------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/guix/http-client.scm b/guix/http-client.scm index 9138a627ac..024705e9ec 100644 --- a/guix/http-client.scm +++ b/guix/http-client.scm @@ -54,6 +54,8 @@ (define-module (guix http-client) http-get-error-reason http-get-error-headers + network-error? + http-fetch http-multiple-get @@ -75,6 +77,27 @@ (define-condition-type &http-get-error &error (reason http-get-error-reason) ;string (headers http-get-error-headers)) ;alist +(define kind-and-args-exception? + (exception-predicate &exception-with-kind-and-args)) + +(define (system-error? exception) + "Return true if EXCEPTION is a Guile 'system-error exception." + (and (kind-and-args-exception? exception) + (eq? 'system-error (exception-kind exception)))) + +(define network-error? + (let ((kind-and-args? (exception-predicate &exception-with-kind-and-args))) + (lambda (exception) + "Return true if EXCEPTION denotes a networking error." + (or (and (system-error? exception) + (let ((errno (system-error-errno + (cons 'system-error (exception-args exception))))) + (memv errno (list ECONNRESET ECONNABORTED ETIMEDOUT + ECONNREFUSED EHOSTUNREACH + ENOENT)))) ;for "file://" + (and (kind-and-args? exception) + (memq (exception-kind exception) + '(gnutls-error getaddrinfo-error))))))) (define* (http-fetch uri #:key port (text? #f) (buffered? #t) (open-connection guix:open-connection-for-uri) diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm index c2bc16085d..362d9fbe7a 100755 --- a/guix/scripts/substitute.scm +++ b/guix/scripts/substitute.scm @@ -577,26 +577,6 @@ (define* (download-nar narinfo destination (values expected (get-hash))))) -(define (system-error? exception) - "Return true if EXCEPTION is a Guile 'system-error exception." - (and (kind-and-args-exception? exception) - (eq? 'system-error (exception-kind exception)))) - -(define network-error? - (let ((kind-and-args? (exception-predicate &exception-with-kind-and-args))) - (lambda (exception) - "Return true if EXCEPTION denotes a networking error." - (or (and (system-error? exception) - (let ((errno (system-error-errno - (cons 'system-error (exception-args exception))))) - (memv errno (list ECONNRESET ECONNABORTED ETIMEDOUT - ECONNREFUSED EHOSTUNREACH - ENOENT)))) ;for "file://" - (and (kind-and-args? exception) - (memq (exception-kind exception) - '(gnutls-error getaddrinfo-error))) - (http-get-error? exception))))) - (define* (process-substitution/fallback narinfo destination #:key cache-urls acl deduplicate? print-build-trace? @@ -623,7 +603,8 @@ (define* (process-substitution/fallback narinfo destination (if (or (equivalent-narinfo? narinfo alternate) (valid-narinfo? alternate acl) (%allow-unauthenticated-substitutes?)) - (guard (c ((network-error? c) + (guard (c ((or (http-get-error? c) + (network-error? c)) (when (http-get-error? c) (warning (G_ "download from '~a' failed: ~a, ~s~%") (uri->string (http-get-error-uri c)) @@ -663,7 +644,8 @@ (define* (process-substitution store-item destination (let ((expected-hash actual-hash (guard - (c ((network-error? c) + (c ((or (http-get-error? c) + (network-error? c)) (when (http-get-error? c) (warning (G_ "download from '~a' failed: ~a, ~s~%") (uri->string (http-get-error-uri c))