Permalink
Browse files

Hooked in express plugin with express's nice error reporting stuff.

  • Loading branch information...
1 parent 33e521b commit 5d0d79f4b9de8efac27608135c993bfc574d5115 @benekastah benekastah committed with Sep 9, 2011
Showing with 13 additions and 1 deletion.
  1. +13 −1 src/coffeekup.coffee
View
@@ -336,8 +336,20 @@ unless window?
# Allows `partial 'foo'` instead of `text @partial 'foo'`.
express:
+ TemplateError: class extends Error
+ constructor: (@message) ->
+ Error.call this, @message
+ Error.captureStackTrace this, arguments.callee
+ name: "TemplateError"
compile: (template, data) ->
data.hardcode ?= {}
data.hardcode.partial = ->
text @partial.apply @, arguments
- coffeekup.compile(template, data)
+
+ TemplateError = @TemplateError
+ try tpl = coffeekup.compile(template, data)
+ catch e then throw new TemplateError "Error compiling #{data.filename}: #{e.message}"
+
+ return ->
+ try tpl arguments...
+ catch e then throw new TemplateError "Error rendering #{data.filename}: #{e.message}"

0 comments on commit 5d0d79f

Please sign in to comment.