CoffeeScript Compilation: Unexpected IF

I am writing CoffeeScript code for an API, and in the catching section of my code I have posted an IF statement. Now, during the compilation process, CoffeeScript says 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

Mistake

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

Does anyone have any ideas where the problem is in my code?

+4
source share
3 answers

Unexpected "INDENT" in CoffeeScript Code Example

This problem looks somewhat similar.

Consider, thus, checking tabs and spaces in your editor.

+6
source

Watch the indentation of long conditions, for example:

if condition and other_condition and
yet_another_condition
^^

he should be

if condition and other_condition and
  yet_another_condition

For example, Intellij breaks this indent

+1
source

, :

Javascript

if (condition) {
    //logic
}

CoffeeScript

if condition
    # logic
# END if
+1

Source: https://habr.com/ru/post/1528841/


All Articles