improve error messages (closes #207)

pull/218/head
Matthew Butterick 5 years ago
parent 70b975b2ce
commit c16979325e

@ -1 +1 @@
1573328416 1573398728

@ -152,11 +152,18 @@
(reset-mod-date-hash!) (reset-mod-date-hash!)
(define expanded-source-paths (define expanded-source-paths
(let loop ([paths paths-in] [acc null]) (let loop ([paths paths-in] [acc null])
(match (and (pair? paths) (->complete-path (car paths))) (match paths
[#false (sort (remove-duplicates acc) string<? #:key path->string)] [(? null?) (sort (remove-duplicates acc) string<? #:key path->string)]
[(? pagetree-source? pt) (loop (append (pagetree->paths pt) (cdr paths)) acc)] [(cons path rest)
[(app ->source-path (and (not #false) (? file-exists?) sp)) (loop (cdr paths) (cons sp acc))] (match (->complete-path path)
[_ (loop (cdr paths) acc)]))) [(? pagetree-source? pt)
(loop (append (pagetree->paths pt) rest) acc)]
[(app ->source-path (and (not #false) (? file-exists?) sp))
(loop rest (cons sp acc))]
[(or (? file-exists?) (? directory-exists?)) (loop rest acc)]
[unknown (raise-user-error 'render-batch
"~a is not a source path, directory, or output path"
unknown)])])))
(cond (cond
[(null? expanded-source-paths) (message "[no paths to render]")] [(null? expanded-source-paths) (message "[no paths to render]")]
[wants-dry-run? (for-each message expanded-source-paths)] [wants-dry-run? (for-each message expanded-source-paths)]
@ -196,7 +203,7 @@
(define output-path (cond (define output-path (cond
[maybe-output-path] [maybe-output-path]
[(->output-path source-path)] [(->output-path source-path)]
[else (raise-argument-error caller "valid output path" output-path)])) [else (raise-argument-error caller "valid output path" maybe-output-path)]))
(define template-path (cond (define template-path (cond
[maybe-template-path] [maybe-template-path]
[(get-template-for source-path output-path)] [(get-template-for source-path output-path)]
@ -320,17 +327,16 @@
(cond (cond
[maybe-output-path] [maybe-output-path]
[(->output-path source-path)] [(->output-path source-path)]
[else (raise-argument-error 'render-markup-or-markdown-source "valid output path" output-path)])) [else (raise-argument-error 'render-markup-or-markdown-source "valid output path" maybe-output-path)]))
(define template-path (define template-path
(cond (cond
[maybe-template-path] [maybe-template-path]
[(get-template-for source-path output-path)] [(get-template-for source-path output-path)]
[else (raise-argument-error 'render-markup-or-markdown-source [else (raise-user-error 'render-markup-or-markdown-source
(format "valid template path~a" "couldn't find template~a"
(if (has-inner-poly-ext? source-path) (if (has-inner-poly-ext? source-path)
(format " for target ~a" (current-poly-target)) (format " for target .~a" (current-poly-target))
"")) ""))]))
template-path)]))
;; use a temp file so that multiple (possibly parallel) renders ;; use a temp file so that multiple (possibly parallel) renders
;; do not compete for write access to the same template ;; do not compete for write access to the same template

Loading…
Cancel
Save