unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#41956: [PATCH] ice-9: exceptions: Properly format the error message.
@ 2020-06-19 21:33 Maxim Cournoyer
  2020-06-20  5:46 ` maxim.cournoyer
  2021-06-02  7:32 ` bug#41956: is this still current ? Adriano Peluso
  0 siblings, 2 replies; 12+ messages in thread
From: Maxim Cournoyer @ 2020-06-19 21:33 UTC (permalink / raw)
  To: 41956

[-- Attachment #1: Type: text/plain, Size: 1286 bytes --]

Hello,

I had this problem in Guix where 'guix deploy my-config.scm' would
unhelpfully report an error like:

guix deploy: error: failed to deploy my-host: ~A: ~S

Digging a bit, I could reproduce at the REPL with:

--8<---------------cut here---------------start------------->8---
(guard (c ((message-condition? c)
           (format #t "error: ~a~%" (condition-message c))))
  ;; This is what (canonicalize-path "/do/not/exist) ends up doing:
  (throw 'system-error "canonicalize-path" "~A" '("No such file or directory")))

--> error: ~A
--8<---------------cut here---------------end--------------->8---

It seems our native -> srfi-34 style exception converter should populate
the message field with a formatted message, given that's what happens to
present errors as explained in libguile/error.c:

    When an error is reported,\n
    "these are replaced by formatting the corresponding members of\n"
    "@var{args}: @code{~A} (was @code{%s} in older versions of\n"
    "Guile) formats using @code{display} and @code{~S}

I'm not sure about the second ~S that appeared in the Guix output;
possibly the exception got re-thrown and suffered from a slightly
different conversion problem?

Anyway, the simple patch attached should fix the "~A" exception message.

Thank you,

Maxim


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ice-9-exceptions-Properly-format-the-error-message.patch --]
[-- Type: text/x-patch, Size: 1248 bytes --]

From adaa2f66fec7684e9e65491158afc5923613e3da Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Fri, 19 Jun 2020 14:30:05 -0400
Subject: [PATCH] ice-9: exceptions: Properly format the error message.

Before this change, native exceptions such as system errors caught with
srfi-34's `guard' would be converted to an exception with its message
unhelpfully set to "~A".

Thus, apply the message arguments to the message format to derive a human
readable exception message.

* module/ice-9/exceptions.scm (guile-common-exceptions): Format the
message string using its arguments.
---
 module/ice-9/exceptions.scm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/module/ice-9/exceptions.scm b/module/ice-9/exceptions.scm
index 143e7aa3e..c990790e9 100644
--- a/module/ice-9/exceptions.scm
+++ b/module/ice-9/exceptions.scm
@@ -189,7 +189,7 @@
           ((subr msg margs . _)
            (make-exception
             (make-exception-with-origin subr)
-            (make-exception-with-message msg)
+            (make-exception-with-message (apply format #f msg margs))
             (make-exception-with-irritants margs)))
           (_ (make-exception-with-irritants args)))
          args))
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-11-10  4:17 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-19 21:33 bug#41956: [PATCH] ice-9: exceptions: Properly format the error message Maxim Cournoyer
2020-06-20  5:46 ` maxim.cournoyer
2020-06-20 18:33   ` Bengt Richter
2020-06-21  3:49     ` Maxim Cournoyer
2020-06-25 10:04       ` Ricardo Wurmus
2020-06-25 16:33         ` Bengt Richter
2020-06-28  4:25           ` Maxim Cournoyer
2020-06-28 18:23             ` Bengt Richter
2020-06-28  4:17         ` Maxim Cournoyer
2020-06-28  4:31           ` Ricardo Wurmus
2021-06-02  7:32 ` bug#41956: is this still current ? Adriano Peluso
2023-11-10  4:17   ` Maxim Cournoyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).