civodul pushed a commit to branch master
in repository guix.

commit f7f31c85956c6bd2c187452040b13d77a88bf532
Author: Ludovic Courtès <[email protected]>
AuthorDate: Sun Apr 28 23:19:40 2024 +0200

    publish: Catch all compression errors.
    
    * guix/scripts/publish.scm (swallow-zlib-error): Remove.
    (exception-with-kind-and-args?): New variable.
    (swallow-compression-error): New macro.
    (http-write): Use it instead of ‘swallow-zlib-error’.
    
    Change-Id: I835a1eddd9686741d48365ed37f82b1e1d6f6bdd
---
 guix/scripts/publish.scm | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm
index 4457be1fce..a000c559a7 100644
--- a/guix/scripts/publish.scm
+++ b/guix/scripts/publish.scm
@@ -1,7 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2015 David Thompson <[email protected]>
 ;;; Copyright © 2020 by Amar M. Singh <[email protected]>
-;;; Copyright © 2015-2022 Ludovic Courtès <[email protected]>
+;;; Copyright © 2015-2022, 2024 Ludovic Courtès <[email protected]>
 ;;; Copyright © 2020 Maxim Cournoyer <[email protected]>
 ;;; Copyright © 2021 Simon Tournier <[email protected]>
 ;;; Copyright © 2021, 2022 Mathieu Othacehe <[email protected]>
@@ -869,12 +869,23 @@ example: \"/foo/bar\" yields '(\"foo\" \"bar\")."
           (values)
           (apply throw args)))))
 
-(define-syntax-rule (swallow-zlib-error exp ...)
-  "Swallow 'zlib-error' exceptions raised by EXP..."
-  (catch 'zlib-error
+(define exception-with-kind-and-args?
+  (exception-predicate &exception-with-kind-and-args))
+
+(define-syntax-rule (swallow-compression-error exp ...)
+  "Swallow 'zlib-error', 'zstd-error', and 'lzlib-error' exceptions raised by
+EXP..."
+  (with-exception-handler (lambda (exception)
+                            (if (and (exception-with-kind-and-args? exception)
+                                     (memq (exception-kind exception)
+                                           '(zlib-error
+                                             zstd-error
+                                             lzlib-error)))
+                                #f
+                                (raise-exception exception)))
     (lambda ()
       exp ...)
-    (const #f)))
+    #:unwind? #t))
 
 (define (nar-compressed-port port compression)
   "Return a port on which to write the body of the response of a /nar request,
@@ -972,10 +983,10 @@ blocking."
             ;; the only way to avoid building the whole nar in memory, which
             ;; could quickly become a real problem.  As a bonus, we even do
             ;; sendfile(2) directly from the store files to the socket.
-            (swallow-zlib-error
+            (swallow-compression-error
              (swallow-EPIPE
               (write-file (utf8->string body) port)))
-            (swallow-zlib-error
+            (swallow-compression-error
              (close-port port)
              (unless keep-alive?
                (close-port client)))

Reply via email to