mailer icon indicating copy to clipboard operation
mailer copied to clipboard

Add more descriptive error message for "template not found" error case

Open jsyrjala opened this issue 12 years ago • 6 comments

If I attempt to refer to a template that doesn't exist, like this

(defn send-email [name email]
  (deliver-email {:from "[email protected]", :to [email] :subject "my-subject"}
                 "templates/email/not-found.moustache" 
                 {:name name :email email}))

I get following rather cryptic exception:

IllegalArgumentException No implementation of method: :make-reader of protocol: 
#'clojure.java.io/IOFactory found for class: nil  clojure.core/-cache-protocol-fn (core_deftype.clj:541)

Something like this would be better: IllegalArgumentException Template 'templates/email/not-found.moustache' was not found

jsyrjala avatar Jul 13 '13 21:07 jsyrjala

Good idea!

michaelklishin avatar Jul 14 '13 00:07 michaelklishin

This error message comes from https://github.com/fhd/clostache/blob/master/src/clostache/parser.clj#L375

Currently in mailer, there is no validation check on template resource. There are two options:

  1. Add validation check for template resource in Mailer
  2. Enhance upstream library (in this case clostache).

I also notice there is another ticket https://github.com/clojurewerkz/mailer/issues/3. If mailer will switch from clostache to stencil, it is better idea to enhance stencil as well.

Note: stencil has slightly different way to find resource, it tries to find resource with/without postfix ".mustache".

I can enhance it, but I would like to get your opinion before taking the effort.

Thanks.

tendant avatar Jul 26 '14 16:07 tendant

We'll be moving away from Clostache. I'm curious if Stencil produces a better error message?

michaelklishin avatar Jul 26 '14 16:07 michaelklishin

Not much difference.

This is the error coming from Stencil with no template.

IllegalArgumentException No implementation of method: :render of protocol: #'stencil.ast/ASTNode found for class: nil clojure.core/-cache-protocol-fn (core_deftype.clj:544)

tendant avatar Jul 26 '14 16:07 tendant

OK, I'm all for having a check in Mailer that produces a more indicative message. Feel free to submit a PR.

michaelklishin avatar Jul 26 '14 16:07 michaelklishin

Will do.

tendant avatar Jul 26 '14 16:07 tendant