mbutterick/pollen

Better error messages?

Closed this issue · 5 comments

(This is potentially a WONTFIX)

Issue 1: missing template

If I have the following setup:

(module setup racket/base
  (provide (all-defined-out))
  (define poly-targets '(html tex)))

but doesn't have template.tex.p (or any other kind of templates), when running raco pollen render foo.tex (where foo.poly.pm is the source file), there will be the following error:

pollen: rendering foo.tex
render-markup-or-markdown-source: contract violation
  expected: valid template path for target tex
  given: #f
  context...:
   /Users/sorawee/Library/Racket/7.4/pkgs/pollen/pollen/render.rkt:299:0: render-markup-or-markdown-source30
   /Users/sorawee/Library/Racket/7.4/pkgs/pollen/pollen/render.rkt:218:25: render25
   /Users/sorawee/Library/Racket/7.4/pkgs/pollen/pollen/private/cache-utils.rkt:106:2: generate-dest-file
   /Applications/Racket v7.4/collects/file/cache.rkt:63:2: fetch-and-continue
   /Applications/Racket v7.4/collects/racket/contract/private/arrow-val-first.rkt:430:3
   /Users/sorawee/Library/Racket/7.4/pkgs/pollen/pollen/private/cache-utils.rkt:97:0: cache-ref!12
   /Users/sorawee/Library/Racket/7.4/pkgs/pollen/pollen/render.rkt:151:25: render-from-source-or-output-path
   /Users/sorawee/Library/Racket/7.4/pkgs/pollen/pollen/render.rkt:51:25: render-batch4
   /Users/sorawee/Library/Racket/7.4/pkgs/pollen/pollen/private/external/logging.rkt:46:0
   (submod "/Users/sorawee/Library/Racket/7.4/pkgs/pollen/pollen/private/command.rkt" raco): [running body]
   temp37_0
   for-loop
   run-module-instance!125
   "/Applications/Racket v7.4/collects/raco/raco.rkt": [running body]
   temp37_0
   for-loop
   ...

While the error does mention "valid template path for target tex", it's still a pretty obscure error message and looks like internal errors. Can this be improved in any way?

Issue 2: missing files

If I raco pollen render asdqwe where asdqwe doesn't exist at all (both as an input file and output file), Pollen still seems to be happy and just output:

pollen: rendering asdqwe

I expect an error to occur along with a descriptive error message.

it's still a pretty obscure error message and looks like internal errors. Can this be improved in any way?

What would be a better way of presenting the error?

I think in this case raise-user-error would be more appropriate than contract errors. To quote https://docs.racket-lang.org/reference/exns.html#%28def._%28%28quote._~23~25kernel%29._raise-user-error%29%29:

so raise-user-error should be used for errors that are intended for end users.

OK, changed those error types.

After trying it out, I don’t like the ergonomics of raising an error for a missing file. So I’ve reverted it (to just being a no-op).

In my case, I tried rendering a certain pagetree where a couple underlying source files had been deleted. Before, the render would proceed normally. But this time, I had to go through the pagetree and delete every missing file before I could render. It just felt like pointless homework.

However, if you do raco pollen render asdqwe you will now be told:

pollen: rendering asdqwe
pollen: [no paths to render]

Thanks!