* A little better layout for configuration reading code

* Improved comment about it
* Use `raise-user-error' to avoid redundant context printout
* Check that the configuration content is a proper alist

svn: r16338
This commit is contained in:
Eli Barzilay 2009-10-16 14:01:43 +00:00
parent aa2e094311
commit 5aea2eeca3

View File

@ -27,18 +27,26 @@
(let ([filetime (file-or-directory-modify-seconds config-file)])
(unless (and filetime (equal? filetime last-filetime))
(set! last-filetime filetime)
(set! raw-config
(with-handlers ([void (lambda (e)
(error 'get-conf
"could not read conf (~a): ~a"
config-file
(exn-message e)))])
(with-handlers
([void (lambda (e)
(raise-user-error 'get-conf "could not read conf (~a): ~a"
config-file (exn-message e)))])
(when raw-config
;; can't use log-line from logger, since it makes a cycle
;; can't use log-line from logger, since it makes a cycle,
;; but make sure it's written in one shot; in any case, don't
;; write anything if this is the first read, since the logger
;; is not initialized yet (and if there's an error at this
;; stage, the server will exit)
(fprintf (current-error-port)
(format "loading configuration from ~a\n"
(format "reloading configuration from ~a\n"
config-file)))
(with-input-from-file config-file read)))
(let ([c (with-input-from-file config-file read)])
(if (and (list? c)
(andmap (lambda (x)
(and (pair? x) (symbol? (car x))))
c))
(set! raw-config c)
(error "malformed configuration file content"))))
(set! config-cache (make-hasheq)))))
(hash-ref config-cache key
(lambda ()