guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

05/06: Provide more information if the server can't bind the port


From: Christopher Baines
Subject: 05/06: Provide more information if the server can't bind the port
Date: Sat, 14 Mar 2020 09:15:27 -0400 (EDT)

cbaines pushed a commit to branch master
in repository data-service.

commit 865e856e8fdaf9a193bf506b23788baf22b45559
Author: Christopher Baines <address@hidden>
AuthorDate: Sat Mar 14 13:13:48 2020 +0000

    Provide more information if the server can't bind the port
    
    As this could be a common problem.
---
 guix-data-service/web/server.scm | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/guix-data-service/web/server.scm b/guix-data-service/web/server.scm
index 4f81d4c..452ce6c 100644
--- a/guix-data-service/web/server.scm
+++ b/guix-data-service/web/server.scm
@@ -19,9 +19,11 @@
 (define-module (guix-data-service web server)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-11)
+  #:use-module (ice-9 match)
   #:use-module (web http)
   #:use-module (web request)
   #:use-module (web uri)
+  #:use-module (system repl error-handling)
   #:use-module (fibers web server)
   #:use-module (guix-data-service web controller)
   #:use-module (guix-data-service web util)
@@ -46,8 +48,23 @@
          (run-controller controller request body secret-key-base)))
 
 (define (start-guix-data-service-web-server port host secret-key-base)
-  (run-server (lambda (request body)
-                (handler request body controller
-                         secret-key-base))
-              #:host host
-              #:port port))
+  (call-with-error-handling
+   (lambda ()
+     (run-server (lambda (request body)
+                   (handler request body controller
+                            secret-key-base))
+                 #:host host
+                 #:port port))
+   #:on-error 'backtrace
+   #:post-error (lambda (key . args)
+                  (when (eq? key 'system-error)
+                    (match args
+                      (("bind" "~A" ("Address already in use") _)
+                       (simple-format
+                        (current-error-port)
+                        "\n
+error: guix-data-service could not start, as it could not bind to port ~A
+
+Check if it's already running, or whether another process is using that
+port. Also, the port used can be changed by passing the --port option.\n"
+                        port)))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]