From patchwork Tue Jun 29 10:52:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Tournier X-Patchwork-Id: 30772 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 C36BE27BC81; Tue, 29 Jun 2021 11:54:17 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,SPF_HELO_PASS, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id ECF6E27BC78 for ; Tue, 29 Jun 2021 11:54:16 +0100 (BST) Received: from localhost ([::1]:56444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyBNg-0003fd-07 for patchwork@mira.cbaines.net; Tue, 29 Jun 2021 06:54:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33246) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyBNU-0003e6-0S for guix-patches@gnu.org; Tue, 29 Jun 2021 06:54:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:42144) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lyBNT-0000Dt-B7 for guix-patches@gnu.org; Tue, 29 Jun 2021 06:54:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lyBNT-0007qR-AW for guix-patches@gnu.org; Tue, 29 Jun 2021 06:54:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49196] [PATCH v5 3/3] import: go: Improve error handling. Resent-From: zimoun Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 29 Jun 2021 10:54:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49196 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49196@debbugs.gnu.org Cc: iskarian@mgsn.dev, zimoun Received: via spool by 49196-submit@debbugs.gnu.org id=B49196.162496398830080 (code B ref 49196); Tue, 29 Jun 2021 10:54:03 +0000 Received: (at 49196) by debbugs.gnu.org; 29 Jun 2021 10:53:08 +0000 Received: from localhost ([127.0.0.1]:53688 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lyBMZ-0007p6-TA for submit@debbugs.gnu.org; Tue, 29 Jun 2021 06:53:08 -0400 Received: from mail-wm1-f44.google.com ([209.85.128.44]:44920) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lyBMS-0007o5-69 for 49196@debbugs.gnu.org; Tue, 29 Jun 2021 06:53:02 -0400 Received: by mail-wm1-f44.google.com with SMTP id m9-20020a05600c3b09b02901f246b43bbeso62521wms.3 for <49196@debbugs.gnu.org>; Tue, 29 Jun 2021 03:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6GnBx654lagXlXKu1Fv1bgbXFV7lglLDoD95AU3q25o=; b=Jxk7jmw7Ttio7H3lfp7HCYx4Ie+kmScR8UWwt+VX7N7PGmWed9/s7fb9gW0IcyyRcz Ah0NFFbxWnZNZWtgr+loBBROW0nRmIsGoQ+qlB5xz9oloaNzex0fGS/Jsc2wKcG0rlzM r2cMza1Ij2OM1+DP5vAVC1csaraDOrTly1hw6oK8G/dP+lhg5yV+VDGKd71u7NhFbNOn XIxD/CZEYQkxdWjsfoHvvRT0l7jRCYhs3AwNr+pIOEgGDEiVmZQREd7K1HKbuCiD2H6x 4Th+qXX4NmmPOqQ1e0/fIxqWjf6oTLdShSvewGzFWwkJ23w+20Vp4Rtht2WPIh6TebLA /IDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6GnBx654lagXlXKu1Fv1bgbXFV7lglLDoD95AU3q25o=; b=Z0bkbc93v0REoHHKKkxU455TJTwvJuTWRFsCCJbt0kxljF6GExsFS8dd5iBklom/ao 2hC9wJC8H4h7mYfDPxaN0TFj9ZRkSicJao10lz19Bjb4dGWs7PQwo5l90jSADABrIm8f uEwBloLB1FnaNTfQXMZcikrI3KCyqwBd4dB4O/3LUBvQ12tZ7i8rnzF7m+UQeiXACiEd laqCTKTGt2H4uzZffxXjDrYh8iqPNsalpauccHeLe3Ukbs7B+G+HSIxlDIEBeRjdGxbj iHovlww5HeH5C6MayUHyGGELM0iDoQabELMYAZTOktCfFQpjrX0A/fdUNYs8EUZ1oFxA biGQ== X-Gm-Message-State: AOAM532UeCM+bSPMu3unYIEhovaDnQ71hRDwMlLVZTXiTHyh0dW/AwWx sgVI7xdyjgrteN31FiQx9aWaERs2BdY= X-Google-Smtp-Source: ABdhPJyrxx5G4F+mj5EcSTZJ/fOoMOzIn6eTl02c8MdXQ9obfTtaj5cH1CC1gEfdlANwXORC8cicrQ== X-Received: by 2002:a05:600c:4ecd:: with SMTP id g13mr32295835wmq.174.1624963974492; Tue, 29 Jun 2021 03:52:54 -0700 (PDT) Received: from localhost.localdomain ([193.48.40.110]) by smtp.gmail.com with ESMTPSA id c7sm17784794wrs.23.2021.06.29.03.52.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 03:52:54 -0700 (PDT) From: zimoun Date: Tue, 29 Jun 2021 12:52:37 +0200 Message-Id: <20210629105237.45517-3-zimon.toutoune@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210629105237.45517-1-zimon.toutoune@gmail.com> References: <20210629105237.45517-1-zimon.toutoune@gmail.com> 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" X-getmail-retrieved-from-mailbox: Patches * guix/import/go.scm (go-module->guix-package*): Handle errors, remove memoize. (go-module-recursive-import): Remove 'guard', add memoize. * guix/scripts/import/go.scm (guix-import-go): Adjust. * tests/go.scm: Adjust. --- guix/import/go.scm | 52 +++++++++++++++++++++++--------------- guix/scripts/import/go.scm | 6 ++--- tests/go.scm | 2 +- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/guix/import/go.scm b/guix/import/go.scm index a2863c79ad..5bec31201d 100644 --- a/guix/import/go.scm +++ b/guix/import/go.scm @@ -5,7 +5,8 @@ ;;; Copyright © 2021 Maxim Cournoyer ;;; Copyright © 2021 Ludovic Courtès ;;; Copyright © 2021 Xinglu Chen -;; Copyright © 2021 Sarah Morgensen +;;; Copyright © 2021 Sarah Morgensen +;;; Copyright © 2021 Simon Tournier ;;; ;;; This file is part of GNU Guix. ;;; @@ -62,6 +63,7 @@ #:use-module (web uri) #:export (go-module->guix-package + go-module->guix-package* go-module-recursive-import)) ;;; Commentary: @@ -631,7 +633,28 @@ hint: use one of the following available versions ~a\n" dependencies+versions dependencies)))) -(define go-module->guix-package* (memoize go-module->guix-package)) +(define go-module->guix-package* + (lambda args + ;; Disable output buffering so that the following warning gets printed + ;; consistently. + (setvbuf (current-error-port) 'none) + (let ((package-name (match args ((name _ ...) name)))) + (guard (c ((http-get-error? c) + (warning (G_ "Failed to import package ~s. +reason: ~s could not be fetched: HTTP error ~a (~s). +This package and its dependencies won't be imported.~%") + package-name + (uri->string (http-get-error-uri c)) + (http-get-error-code c) + (http-get-error-reason c)) + (values #f '())) + (else + (warning (G_ "Failed to import package ~s. +reason: ~s.~%") + package-name + (exception-args c)) + (values #f '()))) + (apply go-module->guix-package args))))) (define* (go-module-recursive-import package-name #:key (goproxy "https://proxy.golang.org") @@ -641,23 +664,12 @@ hint: use one of the following available versions ~a\n" (recursive-import package-name #:repo->guix-package - (lambda* (name #:key version repo) - ;; Disable output buffering so that the following warning gets printed - ;; consistently. - (setvbuf (current-error-port) 'none) - (guard (c ((http-get-error? c) - (warning (G_ "Failed to import package ~s. -reason: ~s could not be fetched: HTTP error ~a (~s). -This package and its dependencies won't be imported.~%") - name - (uri->string (http-get-error-uri c)) - (http-get-error-code c) - (http-get-error-reason c)) - (values #f '()))) - (receive (package-sexp dependencies) - (go-module->guix-package* name #:goproxy goproxy - #:version version - #:pin-versions? pin-versions?) - (values package-sexp dependencies)))) + (memoize + (lambda* (name #:key version repo) + (receive (package-sexp dependencies) + (go-module->guix-package* name #:goproxy goproxy + #:version version + #:pin-versions? pin-versions?) + (values package-sexp dependencies)))) #:guix-name go-module->guix-package-name #:version version)) diff --git a/guix/scripts/import/go.scm b/guix/scripts/import/go.scm index 74e8e60cce..071ecdb2ef 100644 --- a/guix/scripts/import/go.scm +++ b/guix/scripts/import/go.scm @@ -115,10 +115,10 @@ that are not yet in Guix")) (map package->definition* (apply go-module-recursive-import arguments)) ;; Single import. - (let ((sexp (apply go-module->guix-package arguments))) + (let ((sexp (apply go-module->guix-package* arguments))) (unless sexp - (leave (G_ "failed to download meta-data for module '~a'~%") - module-name)) + (leave (G_ "failed to download meta-data for module '~a'.~%") + name)) (package->definition* sexp)))))) (() (leave (G_ "too few arguments~%"))) diff --git a/tests/go.scm b/tests/go.scm index b088ab50d2..929a8b39d1 100644 --- a/tests/go.scm +++ b/tests/go.scm @@ -286,6 +286,6 @@ package.") (nix-base32-string->bytevector "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5") #f))) - (go-module->guix-package "github.com/go-check/check"))))))) + (go-module->guix-package* "github.com/go-check/check"))))))) (test-end "go")