me
/
guix
Archived
1
0
Fork 0

import: go: Improve error handling.

* 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.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
master
zimoun 2021-08-06 11:05:17 -07:00 committed by Ludovic Courtès
parent f95bdeb93a
commit be13e2be08
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
3 changed files with 35 additions and 23 deletions

View File

@ -6,6 +6,7 @@
;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz> ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev> ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -63,6 +64,7 @@
#:use-module (web uri) #:use-module (web uri)
#:export (go-module->guix-package #:export (go-module->guix-package
go-module->guix-package*
go-module-recursive-import)) go-module-recursive-import))
;;; Commentary: ;;; Commentary:
@ -646,7 +648,28 @@ hint: use one of the following available versions ~a\n"
dependencies+versions dependencies+versions
dependencies)))) 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 (define* (go-module-recursive-import package-name
#:key (goproxy "https://proxy.golang.org") #:key (goproxy "https://proxy.golang.org")
@ -656,19 +679,8 @@ hint: use one of the following available versions ~a\n"
(recursive-import (recursive-import
package-name package-name
#:repo->guix-package #:repo->guix-package
(memoize
(lambda* (name #:key version repo) (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) (receive (package-sexp dependencies)
(go-module->guix-package* name #:goproxy goproxy (go-module->guix-package* name #:goproxy goproxy
#:version version #:version version

View File

@ -112,10 +112,10 @@ that are not yet in Guix"))
(map package->definition* (map package->definition*
(apply go-module-recursive-import arguments)) (apply go-module-recursive-import arguments))
;; Single import. ;; Single import.
(let ((sexp (apply go-module->guix-package arguments))) (let ((sexp (apply go-module->guix-package* arguments)))
(unless sexp (unless sexp
(leave (G_ "failed to download meta-data for module '~a'~%") (leave (G_ "failed to download meta-data for module '~a'.~%")
module-name)) name))
(package->definition* sexp)))))) (package->definition* sexp))))))
(() (()
(leave (G_ "too few arguments~%"))) (leave (G_ "too few arguments~%")))

View File

@ -410,6 +410,6 @@ package.")
(nix-base32-string->bytevector (nix-base32-string->bytevector
"0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5") "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5")
#f))) #f)))
(go-module->guix-package "github.com/go-check/check"))))))) (go-module->guix-package* "github.com/go-check/check")))))))
(test-end "go") (test-end "go")