guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#40643] [PATCH] git-version: Handle invalid arguments gracefully


From: Jakub Kądziołka
Subject: [bug#40643] [PATCH] git-version: Handle invalid arguments gracefully
Date: Wed, 15 Apr 2020 17:18:23 +0200

* guix/git-download.scm (git-version): Add a check for commit ID length.
---
If you're curious for the motivation, see [1]. This took a while to
debug, so I'm hoping to ease this for the next person who inevitably
stumbles upon this. Is a change like this okay?

[1]: http://logs.guix.gnu.org/guix/2020-04-14.log#162809

 guix/git-download.scm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/guix/git-download.scm b/guix/git-download.scm
index 1eae035fc4..40d81c72b9 100644
--- a/guix/git-download.scm
+++ b/guix/git-download.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès 
<address@hidden>
 ;;; Copyright © 2017 Mathieu Lirzin <address@hidden>
 ;;; Copyright © 2017 Christopher Baines <address@hidden>
+;;; Copyright © 2020 Jakub Kądziołka <address@hidden>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -30,6 +31,7 @@
   #:use-module (ice-9 match)
   #:use-module (ice-9 vlist)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-35)
   #:export (git-reference
             git-reference?
             git-reference-url
@@ -170,6 +172,13 @@ HASH-ALGO (a symbol).  Use NAME as the file name, or a 
generic name if #f."
 
 (define (git-version version revision commit)
   "Return the version string for packages using git-download."
+  ;; git-version is almost exclusively executed while modules are being loaded.
+  ;; This makes any errors hide their backtrace. Avoid the mysterious error
+  ;; "Value out of range 0 to N: 7" when the commit ID is too short, which
+  ;; can happen, for example, when the user swapped the revision and commit
+  ;; arguments by mistake.
+  (when (< (string-length commit) 7)
+    (error "git-version: commit ID unexpectedly short"))
   (string-append version "-" revision "." (string-take commit 7)))
 
 (define (git-file-name name version)
-- 
2.26.0






reply via email to

[Prev in Thread] Current Thread [Next in Thread]