Permalink
Browse files

new option for logging errors; fixed error passback problem

  • Loading branch information...
1 parent e933995 commit 3bb07022f4edcb93aff53d246dc95dd7e4ea5257 @malgorithms committed Oct 24, 2012
Showing with 56 additions and 9 deletions.
  1. +6 −1 index.coffee
  2. +9 −1 index.js
  3. +8 −0 lib/engine.js
  4. +1 −1 lib/errorHandler.js
  5. +12 −2 lib/view.js
  6. +1 −1 package.json
  7. +8 −1 src/engine.coffee
  8. +5 −1 src/errorHandler.coffee
  9. +6 −1 src/view.coffee
View
@@ -9,7 +9,12 @@ exports.expressEngine = e
exports.render = e.run
# express 3.x support
-exports.__express = e.run
+exports.__express = (filename, options, cb) ->
+ e.run filename, options, (err, res) ->
+ if err
+ cb new Error(err)
+ else
+ cb null, res
# express 2.x support
exports.compile = require('./lib/view').expressCompile
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,7 +1,7 @@
{
"name": "toffee",
"description": "A NodeJs, Express 3.x, Express 2.x, and browser-side templating language based on CoffeeScript with slicker tokens and syntax. Built with love at OkCupid.",
- "version": "0.0.48",
+ "version": "0.0.49",
"directories": {
"lib": "./lib"
},
View
@@ -11,7 +11,10 @@ class engine
options = options or {}
@verbose = options.verbose or false
@minimize = options.minimize or false
+
@prettyPrintErrors = if options.prettyPrintErrors? then options.prettyPrintErrors else true
+ @prettyLogErrors = if options.prettyLogErrors? then options.prettyLogErrors else true
+
@viewCache = {} # filename -> view
@fsErrorCache = {} # filename -> timestamp last failed
@@ -34,14 +37,17 @@ class engine
__toffee.autoEscape: if set as false, don't escape output of #{} vars by default
###
+ if not options.prettyPrintErrors? then options.prettyPrintErrors = @prettyPrintErrors
+ if not options.prettyLogErrors? then options.prettyLogErrors = @prettyLogErrors
+
if options?.layout
layout_options = {}
layout_options[k] = v for k,v of options when k isnt "layout"
[err, res] = @runSync filename, options
# if we got an error but want to pretty-print by faking ok result
- if err and @prettyPrintErrors
+ if err and @prettyPrintErrors
[err, res] = [null, err]
# if we're using a layout, pub into that
@@ -141,6 +147,7 @@ class engine
fileName: filename
verbose: @verbose
prettyPrintErrors: @prettyPrintErrors
+ prettyLogErrors: @prettyLogErrors
minimize: @minimize
v = new view txt, view_options
@viewCache[filename] = v
View
@@ -78,7 +78,11 @@ class toffeeError
stack = converted_err.stack
for line, i in stack
- rxx_pub = /// Object[\.]pub[\s]\(undefined\:([0-9]+)\:[0-9]+ ///
+ rxx_pub = ///
+ Object[\.].*?pub[\s]\(undefined\:([0-9]+)\:[0-9]+
+ |
+ tmpl[\.]render[\.]tmpl[\.]pub.*\(undefined\:([0-9]+)\:[0-9]+
+ ///
m = line.match rxx_pub
in_src_file = false
lrange = [null, null]
View
@@ -159,6 +159,7 @@ class view
@verbose = options.verbose or false
@fsError = options.fsError or false # pass true if you could not load the view template and passed in error text
@prettyPrintErrors = if options.prettyPrintErrors? then options.prettyPrintErrors else true
+ @prettyLogErrors = if options.prettyLogErrors? then options.prettyLogErrors else false
@txt = txt
@tokenObj = null # constructed as needed
@coffeeScript = null # constructed as needed
@@ -222,10 +223,14 @@ class view
@error = new toffeeError @, errorTypes.RUNTIME, e
if @error
+ if @prettyLogErrors
+ txt = @error.getPrettyPrintText()
+ for line in txt.split "\n"
+ console.log "toffee err: #{line}"
if @prettyPrintErrors
pair = [null, @error.getPrettyPrint()]
else
- pair = [null, @error.getPrettyPrintText()]
+ pair = [@error.getPrettyPrintText(), null]
if @error.errType is errorTypes.RUNTIME
# don't hold onto runtime errors after value returned.
@error = null

0 comments on commit 3bb0702

Please sign in to comment.