Skip to content

Commit

Permalink
better error handling for coffee script compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cengebretson committed Apr 1, 2013
1 parent 17f9a02 commit a1634b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
15 changes: 10 additions & 5 deletions src/compilers.coffee
Expand Up @@ -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'
Expand Down
7 changes: 3 additions & 4 deletions src/package.coffee
Expand Up @@ -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}\");"
Expand Down

0 comments on commit a1634b2

Please sign in to comment.