* dmd: [PATCH] Improve socket connection errors handling.
@ 2014-04-10 8:14 Cyprien Nicolas
2014-04-10 14:52 ` Ludovic Courtès
0 siblings, 1 reply; 3+ messages in thread
From: Cyprien Nicolas @ 2014-04-10 8:14 UTC (permalink / raw)
To: guix-devel
[-- Attachment #1.1: Type: text/plain, Size: 284 bytes --]
My first patch for dmd :-)
I thought about moving the interior format call to support.scm
(caught-error), but I wanted to keep the patch simple, and not making
two differents changes in one patch (error handling, support
improvements).
Comments welcome.
--
Cyprien/Fulax
[-- Attachment #1.2: 0001-Improve-socket-connection-errors-handling.patch --]
[-- Type: text/x-diff, Size: 1395 bytes --]
From 6e8f871198b661b631a319f3abaef71bc6269fb7 Mon Sep 17 00:00:00 2001
From: Cyprien Nicolas <cyp@fulax.fr>
Date: Thu, 10 Apr 2014 10:07:06 +0200
Subject: [PATCH] Improve socket connection errors handling.
If the user running `deco' does not have the rights privileges to open
the unix socket, the raised exception produces a backtrace.
* modules/dmd/comm.scm (open-connection): Add a (catch
'system-error...) guard around the connect function call.
The handler will abort the program in case of error.
---
modules/dmd/comm.scm | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/modules/dmd/comm.scm b/modules/dmd/comm.scm
index d3743e6..4a0d383 100644
--- a/modules/dmd/comm.scm
+++ b/modules/dmd/comm.scm
@@ -63,7 +63,14 @@ return the socket."
(with-fluids ((%default-port-encoding "UTF-8"))
(let ((sock (socket PF_UNIX SOCK_STREAM 0))
(address (make-socket-address PF_UNIX file)))
- (connect sock address)
+ (catch 'system-error
+ (lambda ()
+ (connect sock address))
+ (lambda (key . args)
+ (display (format #f "Error: Cannot connect to socket `~a': ~a\n"
+ file (apply format #f (cadr args) (caddr args)))
+ (current-error-port))
+ (quit 1)))
sock)))
(define (read-command port)
--
1.8.5.4
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: dmd: [PATCH] Improve socket connection errors handling.
2014-04-10 8:14 dmd: [PATCH] Improve socket connection errors handling Cyprien Nicolas
@ 2014-04-10 14:52 ` Ludovic Courtès
2014-04-10 15:16 ` Cyprien Nicolas
0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2014-04-10 14:52 UTC (permalink / raw)
To: Cyprien Nicolas; +Cc: guix-devel
Cyprien Nicolas <cyprien@nicolas.tf> skribis:
> My first patch for dmd :-)
Very cool, welcome! :-)
Those backtraces had been bothering me for a while too, so thanks for
looking at it.
> From 6e8f871198b661b631a319f3abaef71bc6269fb7 Mon Sep 17 00:00:00 2001
> From: Cyprien Nicolas <cyp@fulax.fr>
> Date: Thu, 10 Apr 2014 10:07:06 +0200
> Subject: [PATCH] Improve socket connection errors handling.
>
> If the user running `deco' does not have the rights privileges to open
> the unix socket, the raised exception produces a backtrace.
>
> * modules/dmd/comm.scm (open-connection): Add a (catch
> 'system-error...) guard around the connect function call.
> The handler will abort the program in case of error.
I pushed a couple of patches that achieve the same result slightly
differently: ‘open-connection’ is left unchanged and it’s the caller’s
responsibility to handle any errors; clients use the new
‘with-system-error-handling’ macro do handle all ‘system-error’
exceptions gracefully.
One remark:
> + (lambda (key . args)
> + (display (format #f "Error: Cannot connect to socket `~a': ~a\n"
> + file (apply format #f (cadr args) (caddr args)))
> + (current-error-port))
This could be directly (format (current-error-port) ...).
Also, we avoid uses of ‘car’, ‘cadr’ etc. in favor of ‘match’ (at least
in new code.)
Thanks!
Ludo’.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: dmd: [PATCH] Improve socket connection errors handling.
2014-04-10 14:52 ` Ludovic Courtès
@ 2014-04-10 15:16 ` Cyprien Nicolas
0 siblings, 0 replies; 3+ messages in thread
From: Cyprien Nicolas @ 2014-04-10 15:16 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guix-devel
[-- Attachment #1: Type: text/plain, Size: 963 bytes --]
Il y a environ 24 minutes, Ludovic Courtès écrivit :
> I pushed a couple of patches that achieve the same result slightly
> differently: ‘open-connection’ is left unchanged and it’s the caller’s
> responsibility to handle any errors; clients use the new
> ‘with-system-error-handling’ macro do handle all ‘system-error’
> exceptions gracefully.
Right, much better and elegant fix :-)
> One remark:
>
> > + (lambda (key . args)
> > + (display (format #f "Error: Cannot connect to socket `~a': ~a\n"
> > + file (apply format #f (cadr args) (caddr args)))
> > + (current-error-port))
>
> This could be directly (format (current-error-port) ...).
I missed that part of the documentation. Thanks for pointing
that out.
> Also, we avoid uses of ‘car’, ‘cadr’ etc. in favor of ‘match’ (at least
> in new code.)
Noted, thanks.
--
Cyprien/Fulax
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-04-10 15:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-10 8:14 dmd: [PATCH] Improve socket connection errors handling Cyprien Nicolas
2014-04-10 14:52 ` Ludovic Courtès
2014-04-10 15:16 ` Cyprien Nicolas
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.