From 1d4d220f58af3ca504cd9df3ce63f031d0e23b9b Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 23 Dec 2018 11:01:38 -0800 Subject: [PATCH] check that source exists (fixes #191) --- pollen/private/ts.rktd | 2 +- pollen/render.rkt | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pollen/private/ts.rktd b/pollen/private/ts.rktd index fdabb35..e21f585 100644 --- a/pollen/private/ts.rktd +++ b/pollen/private/ts.rktd @@ -1 +1 @@ -1545271092 +1545591698 diff --git a/pollen/render.rkt b/pollen/render.rkt index 2d30f48..452c83a 100644 --- a/pollen/render.rkt +++ b/pollen/render.rkt @@ -70,7 +70,7 @@ has/is-markup-source? has/is-scribble-source? has/is-markdown-source?))]) - (pred so-path)) + (pred so-path)) (define-values (source-path output-path) (->source+output-paths so-path)) (render-to-file-if-needed source-path #f output-path)] [(pagetree-source? so-path) (render-pagenodes so-path)]) @@ -84,6 +84,8 @@ source-path maybe-output-path maybe-template-path) + (unless (file-exists? source-path) + (raise-argument-error caller "existing source path" source-path)) (define output-path (or maybe-output-path (->output-path source-path))) (unless output-path (raise-argument-error caller "valid output path" output-path)) @@ -124,6 +126,8 @@ (define+provide/contract (render source-path [maybe-template-path #f] [maybe-output-path #f]) ((complete-path?) ((or/c #f complete-path?) (or/c #f complete-path?)) . ->* . (or/c string? bytes?)) + (unless (file-exists? source-path) + (raise-argument-error 'render "existing source path" source-path)) (define output-path (or maybe-output-path (->output-path source-path))) (unless output-path (raise-argument-error 'render "valid output path" output-path)) @@ -141,7 +145,7 @@ (define render-proc (for/first ([test (in-list tests)] [render-proc (in-list render-procs)] #:when (test source-path)) - render-proc)) + render-proc)) (unless render-proc (raise-argument-error 'render (format "valid rendering function for ~a" source-path) render-proc)) @@ -226,7 +230,7 @@ (define (file-exists-or-has-source? path) ; path could be #f (and path (for/first ([proc (in-list (list values ->preproc-source-path ->null-source-path))] #:when (file-exists? (proc path))) - path))) + path))) (define (get-template-from-metas source-path output-path-ext) (with-handlers ([exn:fail:contract? (λ (e) #f)]) ; in case source-path doesn't work with cached-require @@ -257,7 +261,7 @@ ;; output-path may not have an extension (define output-path-ext (or (get-ext output-path) (current-poly-target))) (for/or ([proc (list get-template-from-metas get-default-template get-fallback-template)]) - (file-exists-or-has-source? (proc source-path output-path-ext)))))) + (file-exists-or-has-source? (proc source-path output-path-ext)))))) (module-test-external (require pollen/setup sugar/file sugar/coerce)