(address . bug-guile@gnu.org)
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:
Toggle snippet (8 lines)
(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
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
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(-)
Toggle diff (15 lines)
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