Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoffeeScript compiling: Unexpected IF

I am writing some CoffeeScript code for an API, and in the error catching section of my code I placed an IF statement. Now, during the compilation process CoffeeScript is saying that the IF statement was unexpected.

#  Handle Errors
app.error (err, req, res, next) ->
    if err instanceof NotFound
        res.send '404, not found.'
    else
        res.send '500, internal server error.'

app.get '/*', (req, res) ->
    throw new NotFound

NotFound = (msg) ->
    this.name = 'NotFound'
    Error.call this, msg
    Error.captureStackTrace this, arguments.callee

The error is

/home/techno/node/snaprss/application.coffee:22:5: error: unexpected if
    if err instanceOf NotFound
    ^^

Does anyone have any ideas where the issue is within my code?

like image 974
TechnoCF Avatar asked Feb 25 '14 21:02

TechnoCF


2 Answers

Unexpected 'INDENT' in CoffeeScript Example Code

This issue looks somehow similar.

Consider therefore checking tabs and spaces in your editor.

like image 69
dnl-blkv Avatar answered Nov 14 '22 23:11

dnl-blkv


Another thing to watch out for parenthesis and braces:

Javascript

if (condition) {
    //logic
}

should be CoffeeScript

if condition
    # logic
# END if
like image 39
Jake Robers Avatar answered Nov 14 '22 22:11

Jake Robers