all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: 60802@debbugs.gnu.org
Cc: Josselin Poiret <dev@jpoiret.xyz>,
	Tobias Geerinckx-Rice <me@tobias.gr>,
	Maxim Cournoyer <maxim.cournoyer@gmail.com>,
	Simon Tournier <zimon.toutoune@gmail.com>,
	Mathieu Othacehe <othacehe@gnu.org>,
	ludo@gnu.org, Christopher Baines <mail@cbaines.net>,
	Ricardo Wurmus <rekado@elephly.net>
Subject: [bug#60802] [PATCH v4 1/2] platforms: Raise an exception when no suitable platform is found.
Date: Tue, 17 Jan 2023 10:34:30 -0500	[thread overview]
Message-ID: <20230117153432.23719-2-maxim.cournoyer@gmail.com> (raw)
In-Reply-To: <20230117153432.23719-1-maxim.cournoyer@gmail.com>

This was motivated by #60786, which produced a cryptic, hard to understand
backtrace.

Given the following reproducer:
    (use-modules (guix packages)
                 (gnu packages cross-base))

    (define linux-libre-headers-cross-mips64el-linux-gnuabi64
      (cross-kernel-headers "mips64el-linux-gnuabi64"))

    (package-arguments linux-libre-headers-cross-mips64el-linux-gnuabi64)

Before this change:
    ice-9/boot-9.scm:1685:16: In procedure raise-exception:
    In procedure struct-vtable: Wrong type argument in position 1 (expecting struct): #f

After this change:
    ice-9/boot-9.scm:1685:16: In procedure raise-exception:
    ERROR:
      1. &platform-not-found-error: "mips64el-linux-gnuabi64"

* guix/platform.scm (&platform-not-found-error): New condition.
(platform-not-found-error?): New predicate.
(false-if-platform-not-found): New syntax.
(lookup-platform-by-system): Raise an exception when no platform is found.
Update documentation.
(lookup-platform-by-target): Likewise.
(lookup-platform-by-target-or-system): Likewise, and guard lookup calls with
false-if-platform-not-found.
* gnu/packages/bootstrap.scm (glibc-dynamic-linker): Handle
lookup-platform-by-system call to preserve existing behavior.

---

Changes in v4:
- Use (srfi srfi-35) condition instead of (ice-9 exceptions)
- Add a target-or-system field to the condition type for extra information

Changes in v3:
- Use false-if-platform-not-found instead of false-if-exception in (gnu
packages bootstrap)
- Do not export make-platform-not-found-error constructor

Changes in v2:
- Add false-if-platform-not-found syntax
- Use it while evaluating lookup-platform-by-target-or-system

 gnu/packages/bootstrap.scm |  3 ++-
 guix/platform.scm          | 55 +++++++++++++++++++++++++++++---------
 2 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/gnu/packages/bootstrap.scm b/gnu/packages/bootstrap.scm
index d2914fb5a7..9ea1a3e4d1 100644
--- a/gnu/packages/bootstrap.scm
+++ b/gnu/packages/bootstrap.scm
@@ -315,7 +315,8 @@ (define* (glibc-dynamic-linker
                                  (%current-system))))
   "Return the name of Glibc's dynamic linker for SYSTEM."
   ;; See the 'SYSDEP_KNOWN_INTERPRETER_NAMES' cpp macro in libc.
-  (let ((platform (lookup-platform-by-system system)))
+  (let ((platform (false-if-platform-not-found
+                   (lookup-platform-by-system system))))
     (cond
      ((platform? platform)
       (platform-glibc-dynamic-linker platform))
diff --git a/guix/platform.scm b/guix/platform.scm
index f873913fe0..a2d95ab507 100644
--- a/guix/platform.scm
+++ b/guix/platform.scm
@@ -22,6 +22,8 @@ (define-module (guix platform)
   #:use-module (guix records)
   #:use-module (guix ui)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35)
   #:export (platform
             platform?
             platform-target
@@ -29,6 +31,10 @@ (define-module (guix platform)
             platform-linux-architecture
             platform-glibc-dynamic-linker
 
+            &platform-not-found-error
+            platform-not-found-error?
+            false-if-platform-not-found
+
             platform-modules
             platforms
             lookup-platform-by-system
@@ -70,6 +76,20 @@ (define-record-type* <platform> platform make-platform
                         (default #false))
   (glibc-dynamic-linker platform-glibc-dynamic-linker))
 
+\f
+;;;
+;;; Exceptions.
+;;;
+(define-condition-type &platform-not-found-error &error
+  platform-not-found-error?
+  (target-or-system platform-not-found-error-target-or-system))
+
+(define-syntax-rule (false-if-platform-not-found exp)
+  "Evaluate EXP but return #f if it raises a platform-not-found-error?
+exception."
+  (guard (ex ((platform-not-found-error? ex) #f))
+    exp))
+
 \f
 ;;;
 ;;; Platforms.
@@ -94,23 +114,32 @@ (define platforms
                                    (platform-modules)))))
 
 (define (lookup-platform-by-system system)
-  "Return the platform corresponding to the given SYSTEM."
-  (find (lambda (platform)
-          (let ((s (platform-system platform)))
-            (and (string? s) (string=? s system))))
-        (platforms)))
+  "Return the platform corresponding to the given SYSTEM.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (find (lambda (platform)
+              (let ((s (platform-system platform)))
+                (and (string? s) (string=? s system))))
+            (platforms))
+      (raise-exception (condition (&platform-not-found-error
+                                   (target-or-system system))))))
 
 (define (lookup-platform-by-target target)
-  "Return the platform corresponding to the given TARGET."
-  (find (lambda (platform)
-          (let ((t (platform-target platform)))
-            (and (string? t) (string=? t target))))
-        (platforms)))
+  "Return the platform corresponding to the given TARGET.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (find (lambda (platform)
+              (let ((t (platform-target platform)))
+                (and (string? t) (string=? t target))))
+            (platforms))
+      (raise-exception (condition (&platform-not-found-error
+                                   (target-or-system target))))))
 
 (define (lookup-platform-by-target-or-system target-or-system)
-  "Return the platform corresponding to the given TARGET or SYSTEM."
-  (or (lookup-platform-by-target target-or-system)
-      (lookup-platform-by-system target-or-system)))
+  "Return the platform corresponding to the given TARGET or SYSTEM.  Raise
+&PLATFORM-NOT-FOUND-ERROR when no platform could be found."
+  (or (false-if-platform-not-found (lookup-platform-by-target target-or-system))
+      (false-if-platform-not-found (lookup-platform-by-system target-or-system))
+      (raise-exception (condition (&platform-not-found-error
+                                   (target-or-system target-or-system))))))
 
 (define (platform-system->target system)
   "Return the target matching the given SYSTEM if it exists or false
-- 
2.38.1





  reply	other threads:[~2023-01-17 15:35 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-14  3:05 [bug#60802] [PATCH 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
2023-01-14  3:08 ` [bug#60802] [PATCH 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
2023-01-14  3:08   ` [bug#60802] [PATCH 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
2023-01-14  4:19 ` [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
2023-01-14  4:19   ` [bug#60802] [PATCH v2 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
2023-01-14 14:34   ` [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found Ludovic Courtès
2023-01-16 17:46     ` Maxim Cournoyer
2023-01-16 20:13       ` Exception: srfi-35 vs (ice-9 exceptions (was Re: [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found.) zimoun
2023-01-16 21:59         ` Maxim Cournoyer
2023-01-17 16:35           ` Ludovic Courtès
2023-01-16 22:35         ` Ricardo Wurmus
2023-01-17 19:58           ` Josselin Poiret
2023-01-19 14:38             ` Ludovic Courtès
2023-01-19 15:59               ` Katherine Cox-Buday
2023-01-17  9:22       ` [bug#60802] [PATCH v2 1/2] platforms: Raise an exception when no suitable platform is found Ludovic Courtès
2023-01-14 14:34   ` Ludovic Courtès
2023-01-19  1:55     ` bug#60802: [PATCH 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
2023-01-14 15:14 ` [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found Maxim Cournoyer
2023-01-14 15:14   ` [bug#60802] [PATCH v3 2/2] gnu: Remove u-boot-malta Maxim Cournoyer
2023-01-15 13:57   ` [bug#60802] [PATCH v3 1/2] platforms: Raise an exception when no suitable platform is found Josselin Poiret via Guix-patches via
2023-01-15 22:11     ` Maxim Cournoyer
2023-01-16 11:00     ` Simon Tournier
2023-01-17  8:59     ` Ludovic Courtès
2023-01-17 12:35       ` Simon Tournier
2023-01-17 14:38         ` Maxim Cournoyer
2023-01-17 15:34 ` [bug#60802] [PATCH v4 0/2] Remove unsupported u-boot-malta package Maxim Cournoyer
2023-01-17 15:34   ` Maxim Cournoyer [this message]
2023-01-17 15:34   ` [bug#60802] [PATCH v4 2/2] gnu: Remove u-boot-malta Maxim Cournoyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230117153432.23719-2-maxim.cournoyer@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=60802@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=ludo@gnu.org \
    --cc=mail@cbaines.net \
    --cc=me@tobias.gr \
    --cc=othacehe@gnu.org \
    --cc=rekado@elephly.net \
    --cc=zimon.toutoune@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.