Skip to content

Commit

Permalink
new option for logging errors; fixed error passback problem
Browse files Browse the repository at this point in the history
  • Loading branch information
malgorithms committed Oct 24, 2012
1 parent e933995 commit 3bb0702
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 9 deletions.
7 changes: 6 additions & 1 deletion index.coffee
Expand Up @@ -9,7 +9,12 @@ exports.expressEngine = e
exports.render = e.run exports.render = e.run


# express 3.x support # 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 # express 2.x support
exports.compile = require('./lib/view').expressCompile exports.compile = require('./lib/view').expressCompile
10 changes: 9 additions & 1 deletion index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions lib/engine.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/errorHandler.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions lib/view.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{ {
"name": "toffee", "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.", "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": { "directories": {
"lib": "./lib" "lib": "./lib"
}, },
Expand Down
9 changes: 8 additions & 1 deletion src/engine.coffee
Expand Up @@ -11,7 +11,10 @@ class engine
options = options or {} options = options or {}
@verbose = options.verbose or false @verbose = options.verbose or false
@minimize = options.minimize or false @minimize = options.minimize or false

@prettyPrintErrors = if options.prettyPrintErrors? then options.prettyPrintErrors else true @prettyPrintErrors = if options.prettyPrintErrors? then options.prettyPrintErrors else true
@prettyLogErrors = if options.prettyLogErrors? then options.prettyLogErrors else true

@viewCache = {} # filename -> view @viewCache = {} # filename -> view
@fsErrorCache = {} # filename -> timestamp last failed @fsErrorCache = {} # filename -> timestamp last failed


Expand All @@ -34,14 +37,17 @@ class engine
__toffee.autoEscape: if set as false, don't escape output of #{} vars by default __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 if options?.layout
layout_options = {} layout_options = {}
layout_options[k] = v for k,v of options when k isnt "layout" layout_options[k] = v for k,v of options when k isnt "layout"


[err, res] = @runSync filename, options [err, res] = @runSync filename, options


# if we got an error but want to pretty-print by faking ok result # 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] [err, res] = [null, err]


# if we're using a layout, pub into that # if we're using a layout, pub into that
Expand Down Expand Up @@ -141,6 +147,7 @@ class engine
fileName: filename fileName: filename
verbose: @verbose verbose: @verbose
prettyPrintErrors: @prettyPrintErrors prettyPrintErrors: @prettyPrintErrors
prettyLogErrors: @prettyLogErrors
minimize: @minimize minimize: @minimize
v = new view txt, view_options v = new view txt, view_options
@viewCache[filename] = v @viewCache[filename] = v
Expand Down
6 changes: 5 additions & 1 deletion src/errorHandler.coffee
Expand Up @@ -78,7 +78,11 @@ class toffeeError
stack = converted_err.stack stack = converted_err.stack
for line, i in 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 m = line.match rxx_pub
in_src_file = false in_src_file = false
lrange = [null, null] lrange = [null, null]
Expand Down
7 changes: 6 additions & 1 deletion src/view.coffee
Expand Up @@ -159,6 +159,7 @@ class view
@verbose = options.verbose or false @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 @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 @prettyPrintErrors = if options.prettyPrintErrors? then options.prettyPrintErrors else true
@prettyLogErrors = if options.prettyLogErrors? then options.prettyLogErrors else false
@txt = txt @txt = txt
@tokenObj = null # constructed as needed @tokenObj = null # constructed as needed
@coffeeScript = null # constructed as needed @coffeeScript = null # constructed as needed
Expand Down Expand Up @@ -222,10 +223,14 @@ class view
@error = new toffeeError @, errorTypes.RUNTIME, e @error = new toffeeError @, errorTypes.RUNTIME, e


if @error if @error
if @prettyLogErrors
txt = @error.getPrettyPrintText()
for line in txt.split "\n"
console.log "toffee err: #{line}"
if @prettyPrintErrors if @prettyPrintErrors
pair = [null, @error.getPrettyPrint()] pair = [null, @error.getPrettyPrint()]
else else
pair = [null, @error.getPrettyPrintText()] pair = [@error.getPrettyPrintText(), null]
if @error.errType is errorTypes.RUNTIME if @error.errType is errorTypes.RUNTIME
# don't hold onto runtime errors after value returned. # don't hold onto runtime errors after value returned.
@error = null @error = null
Expand Down

0 comments on commit 3bb0702

Please sign in to comment.