Permalink
Browse files

better error handling for coffee script compile errors

  • Loading branch information...
1 parent 17f9a02 commit a1634b2127da1fd551b7b4b5dc92e22bd3112b7d @cengebretson cengebretson committed Apr 1, 2013
Showing with 13 additions and 9 deletions.
  1. +10 −5 src/compilers.coffee
  2. +3 −4 src/package.coffee
View
@@ -11,11 +11,16 @@ require.extensions['.css'] = (module, filename) ->
try
cs = require 'coffee-script'
- compilers.coffee = (path) ->
- cs.compile(fs.readFileSync(path, 'utf8'), filename: path)
-
- compilers.litcoffee = (path) ->
- cs.compile(fs.readFileSync(path, 'utf8'), filename: path, literate: true)
+ compilers.coffee = (path) -> compileCoffeescript(path)
+ compilers.litcoffee = (path) -> compileCoffeescript(path, true)
+ compileCoffeescript = (path, literate = false) ->
+ try
+ cs.compile(fs.readFileSync(path, 'utf8'), filename: path, literate: literate)
+ catch err
+ err.message = "Coffeescript Error: " + err.message
+ err.path = "Coffeescript Path: " + path
+ err.path = err.path + ":" + (err.location.first_line + 1) if err.location
+ throw err
catch err
eco = require 'eco'
View
@@ -66,10 +66,9 @@ class Package
#fs.writeFileSync('app.cache', content) if content
handleCompileError: (ex) ->
- if ex.stack
- console.error ex.stack
- else
- console.trace(ex)
+ console.error ex.message
+ console.error ex.path if ex.path
+ console.error ex.location if ex.location
# only return when in server/watch mode, otherwise exit
switch @argv.command
when "server" then return "console.log(\"#{ex}\");"

0 comments on commit a1634b2

Please sign in to comment.