Graceful handling of errors in scripts.
authorTim Vaughan <tgvaughan@gmail.com>
Sun, 5 May 2019 10:18:35 +0000 (12:18 +0200)
committerTim Vaughan <tgvaughan@gmail.com>
Sun, 5 May 2019 10:18:35 +0000 (12:18 +0200)
burrower.scm

index 867a289..a03c266 100644 (file)
@@ -82,7 +82,7 @@
      ((or (= (string-length l) 0) (string-suffix? "/" l)) 1)
      ((has-suffix? l ".txt" ".org" ".md") 0)
      ((has-suffix? l ".png" ".jpg" ".gif" ".bmp" ".tif" ".tga") 'I)
      ((or (= (string-length l) 0) (string-suffix? "/" l)) 1)
      ((has-suffix? l ".txt" ".org" ".md") 0)
      ((has-suffix? l ".png" ".jpg" ".gif" ".bmp" ".tif" ".tga") 'I)
-     ((has-suffix? l "?") 7)
+     ((has-suffix? l "?.scm") 7)
      (else 9))))
 
 
      (else 9))))
 
 
         (error "File not found." file-name))))
 
 (define (serve-query selector arguments remote-ip config)
         (error "File not found." file-name))))
 
 (define (serve-query selector arguments remote-ip config)
-  (let ((file-name (make-pathname (config-root-dir config)
-                                  (conc (string-chomp selector "?") ".scm"))))
+  (let ((file-name (make-pathname (config-root-dir config) selector)))
     (if (and (regular-file? file-name)
              (= (length arguments) 1))
         (with-input-from-file file-name
     (if (and (regular-file? file-name)
              (= (length arguments) 1))
         (with-input-from-file file-name
 (define (with-current-working-directory directory thunk)
   (let ((old-wd (current-directory))
         (result 'none))
 (define (with-current-working-directory directory thunk)
   (let ((old-wd (current-directory))
         (result 'none))
-    (change-directory directory)
-    (set! result (thunk))
-    (change-directory old-wd)
-    result))
+    (condition-case
+        (begin
+          (change-directory directory)
+          (set! result (thunk))
+          (change-directory old-wd)
+          result)
+      (o (exn)
+         (change-directory old-wd)
+         (signal o)))))
 
 (define (with-selector-dir selector config thunk)
   (with-current-working-directory
 
 (define (with-selector-dir selector config thunk)
   (with-current-working-directory