Skip to content
Browse files

custom error handling support

  • Loading branch information...
1 parent 67441dd commit 8963ddd910d576ac25be375f444c72ece7530049 @malgorithms committed Oct 24, 2012
Showing with 27 additions and 11 deletions.
  1. +5 −0 lib/engine.js
  2. +4 −0 lib/view.js
  3. +1 −1 package.json
  4. +13 −10 src/engine.coffee
  5. +4 −0 src/view.coffee
View
5 lib/engine.js
@@ -32,6 +32,7 @@
this.minimize = options.minimize || false;
this.prettyPrintErrors = options.prettyPrintErrors != null ? options.prettyPrintErrors : true;
this.prettyLogErrors = options.prettyLogErrors != null ? options.prettyLogErrors : true;
+ this.additionalErrorHandler = options.additionalErrorHandler || null;
this.viewCache = {};
this.fsErrorCache = {};
}
@@ -68,6 +69,9 @@
if (!(options.prettyLogErrors != null)) {
options.prettyLogErrors = this.prettyLogErrors;
}
+ if (!(options.additionalErrorHandler != null)) {
+ options.additionalErrorHandler = this.additionalErrorHandler;
+ }
if (options != null ? options.layout : void 0) {
layout_options = {};
for (k in options) {
@@ -205,6 +209,7 @@
verbose: this.verbose,
prettyPrintErrors: this.prettyPrintErrors,
prettyLogErrors: this.prettyLogErrors,
+ additionalErrorHandler: this.additionalErrorHandler,
minimize: this.minimize
};
v = new view(txt, view_options);
View
4 lib/view.js
@@ -83,6 +83,7 @@
this.fsError = options.fsError || false;
this.prettyPrintErrors = options.prettyPrintErrors != null ? options.prettyPrintErrors : true;
this.prettyLogErrors = options.prettyLogErrors != null ? options.prettyLogErrors : false;
+ this.additionalErrorHandler = options.additionalErrorHandler || null;
this.txt = txt;
this.tokenObj = null;
this.coffeeScript = null;
@@ -179,6 +180,9 @@
console.log("toffee err: " + line);
}
}
+ if (this.additionalErrorHandler) {
+ this.additionalErrorHandler(this.error.getPrettyPrintText(), this.error.getPrettyPrint(), this.fileName);
+ }
if (this.prettyPrintErrors) {
pair = [null, this.error.getPrettyPrint()];
} else {
View
2 package.json
@@ -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.49",
+ "version": "0.0.50",
"directories": {
"lib": "./lib"
},
View
23 src/engine.coffee
@@ -12,13 +12,14 @@ class engine
@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
+ @prettyPrintErrors = if options.prettyPrintErrors? then options.prettyPrintErrors else true
+ @prettyLogErrors = if options.prettyLogErrors? then options.prettyLogErrors else true
+ @additionalErrorHandler = options.additionalErrorHandler or null
@viewCache = {} # filename -> view
@fsErrorCache = {} # filename -> timestamp last failed
- _log: (o) ->
+ _log: (o) ->
if @verbose
if (typeof o) in ["string","number","boolean"]
console.log "toffee: #{o}"
@@ -37,8 +38,9 @@ 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 not options.prettyPrintErrors? then options.prettyPrintErrors = @prettyPrintErrors
+ if not options.prettyLogErrors? then options.prettyLogErrors = @prettyLogErrors
+ if not options.additionalErrorHandler? then options.additionalErrorHandler = @additionalErrorHandler
if options?.layout
layout_options = {}
@@ -144,11 +146,12 @@ class engine
return @viewCache[filename]
else
view_options =
- fileName: filename
- verbose: @verbose
- prettyPrintErrors: @prettyPrintErrors
- prettyLogErrors: @prettyLogErrors
- minimize: @minimize
+ fileName: filename
+ verbose: @verbose
+ prettyPrintErrors: @prettyPrintErrors
+ prettyLogErrors: @prettyLogErrors
+ additionalErrorHandler: @additionalErrorHandler
+ minimize: @minimize
v = new view txt, view_options
@viewCache[filename] = v
@_monitorForChanges filename, options
View
4 src/view.coffee
@@ -160,6 +160,7 @@ class view
@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
+ @additionalErrorHandler = options.additionalErrorHandler or null
@txt = txt
@tokenObj = null # constructed as needed
@coffeeScript = null # constructed as needed
@@ -227,6 +228,9 @@ class view
txt = @error.getPrettyPrintText()
for line in txt.split "\n"
console.log "toffee err: #{line}"
+ if @additionalErrorHandler
+ @additionalErrorHandler @error.getPrettyPrintText(), @error.getPrettyPrint(), @fileName
+
if @prettyPrintErrors
pair = [null, @error.getPrettyPrint()]
else

0 comments on commit 8963ddd

Please sign in to comment.
Something went wrong with that request. Please try again.