bug#41956: [PATCH] ice-9: exceptions: Properly format the error message.
Hi Maxim, >> here’s what I did in the REPL: >> >> scheme@(guile-user)> ,m (ice-9 exceptions) >> scheme@(ice-9 exceptions)> (define (my/guile-system-error-converter key args) >> (apply (case-lambda >> ((subr msg-args msg errno . rest) Here I changed the order: “msg-args” appears before “msg”. I don’t know why the converter that’s currently in Guile assumes that the message comes first. >> scheme@(ice-9 exceptions)> (set! guile-exception-converters (acons >> 'system-error my/guile-system-error-converter guile-exception-converters)) guile-exception-converters is a lookup table in (ice-9 exceptions). It associates error keys with converter procedures. Since canonicalize-path throws a 'system-error I chose to only update the 'system-error association. I didn’t want to affect all the other converter procedures that end up using the common converter; maybe they should be affected — I don’t know because I don’t have any test cases other than canonicalize-path. > This brings embeds the definition of `guile-common-exceptions' into > `guile-system-error-converter', with a single change: > > (make-exception-with-message msg) --> (apply make-exception-with-message > msg msg-args) > > What is the magic I fail to see? I cannot parse your sentence, so I’m not sure what you mean. > Is this fix proper to be merged into the original > guile-common-exceptions procedure? I think we should add tests of different exceptions with different keys to be sure that modifying the common handler doesn’t have any unexpected side-effects. -- Ricardo
bug#41956: [PATCH] ice-9: exceptions: Properly format the error message.
Hello Bengt, Bengt Richter writes: [...] > What do you think of using (ice-9 match) to make a universal > throwage-formatter, > with the idea of making readable top level code for how exceptions become > messages on screen? > > I started a hack to explore the (throw 'whatever any ...) space, beginning > like > > (use-modules (ice-9 match)) > (define (make-exception-message key rest) > (begin > (let*((l (cons key rest))) > (match l >(('system-error subr message args data ...) > ;; e.g. thrown with key 'system-error: ("open-fdes" "~A" ("No > such file or directory") (2)) > (format #f (string-append "match-1: subr ~s threw '~s " message " > sterror: ~s") subr key args (strerror (car (car data) > >(('signal any ...) > ;; not yet implemented > (format #f "match-2: any: ~s" any)) Are you proposing to refactor (ice-9 exceptions) so that it's simpler to follow a condition message is formed for a given exception type? Maxim
bug#41956: [PATCH] ice-9: exceptions: Properly format the error message.
Hello Ricardo! Ricardo Wurmus writes: > Hi Maxim, > > here’s what I did in the REPL: > > scheme@(guile-user)> ,m (ice-9 exceptions) > scheme@(ice-9 exceptions)> (define (my/guile-system-error-converter key args) > (apply (case-lambda > ((subr msg-args msg errno . rest) >;; XXX TODO we should return a more specific error >;; (usually an I/O error) as expected by R6RS programs. >;; Unfortunately this often requires the 'filename' (or >;; other?) which is not currently provided by the native >;; Guile exceptions. > (make-exception > (make-external-error) > (make-exception-with-origin subr) > (apply make-exception-with-message msg) > (make-exception-with-irritants msg-args))) > (_ (guile-external-error-converter key args))) > args)) > scheme@(ice-9 exceptions)> (set! guile-exception-converters (acons > 'system-error my/guile-system-error-converter guile-exception-converters)) > scheme@(ice-9 exceptions)> ,m (guile-user) > scheme@(guile-user)> (guard (c ((message-condition? c) > (format #t "message: ~a~%" (condition-message c > (canonicalize-path "/doesntexist")) > message: No such file or directory > $11 = #t > scheme@(guile-user)> I've tested that this indeed works, although I don't quite understand how? This brings embeds the definition of `guile-common-exceptions' into `guile-system-error-converter', with a single change: (make-exception-with-message msg) --> (apply make-exception-with-message msg msg-args) What is the magic I fail to see? Is this fix proper to be merged into the original guile-common-exceptions procedure? Thank you! Maxim