summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2016-04-21 22:37:44 -0400
committerDavid Thompson <dthompson2@worcester.edu>2016-04-21 22:37:44 -0400
commit0d67128c3da6413546015fa9092a0017f50d46b9 (patch)
tree83e6e4ad45916d9a1974913c812bf2ab06ac7d5b
parent473868946feab62cf5f73e4ef93a85b54e40c358 (diff)
serve: Catch exceptions when rebuilding site.
Now 'haunt serve --watch' won't crash when you put some bad code in a post! * haunt/ui/server.scm (call-with-error-handling): New procedure. (watch): Wrap build-site call in call-with-error-handling form.
-rw-r--r--haunt/ui/serve.scm17
1 files changed, 16 insertions, 1 deletions
diff --git a/haunt/ui/serve.scm b/haunt/ui/serve.scm
index b6fd01b..53e8c54 100644
--- a/haunt/ui/serve.scm
+++ b/haunt/ui/serve.scm
@@ -70,6 +70,19 @@ Start an HTTP server for the current site.~%")
(cons '(port . 8080)
%default-common-options))
+(define (call-with-error-handling thunk)
+ (catch #t
+ thunk
+ (lambda (key . args)
+ (let ((cep (current-error-port))
+ (stack (make-stack #t 1)))
+ (display "ERROR: site rebuild failed\n\n" cep)
+ (display "Backtrace:\n" cep)
+ (display-backtrace stack cep)
+ (newline cep)
+ (apply display-error (stack-ref stack 0) cep args)
+ (newline cep)))))
+
;; XXX: Make this less naive.
(define (watch config-file check-dir? check-file?)
"Watch the current working directory for changes to any of its files
@@ -100,7 +113,9 @@ site."
(let loop ((time (current-time)))
(when (any-files-changed? time)
(display "rebuilding...\n")
- (build-site (load-config config-file)))
+ (call-with-error-handling
+ (lambda ()
+ (build-site (load-config config-file)))))
(let ((next-time (current-time)))
(sleep 1)
(loop next-time))))