jashkenas/coffee-script — pull request #2723 by epidemian (2013-02-26 04:58:29+00:00)
Title: Improved error messages

So, the awesome pull request by @jwalton, #2696, added source location tracking to the compiler. With that, we can have much better error messages :smile_cat:

If we have a problematic file:

```coffeescript
# error.coffee
for {wat} in [1..10]
wat?
```

Error messages before pull request:

```
SyntaxError: In error.coffee, cannot pattern match over range loops
at SyntaxError (unknown source)
at new For (/home/demian/Programming/coffee-script/lib/coffee-script/nodes.js:2550:15)
at Object.anonymous (/home/demian/Programming/coffee-script/lib/coffee-script/parser.js:325:58)
at Object.parse (/home/demian/Programming/coffee-script/lib/coffee-script/parser.js:565:36)
at Object.exports.compile.compile (/home/demian/Programming/coffee-script/lib/coffee-script/coffee-script.js:46:20)
at compileScript (/home/demian/Programming/coffee-script/lib/coffee-script/command.js:182:33)
at fs.stat.notSources.(anonymous function) (/home/demian/Programming/coffee-script/lib/coffee-script/command.js:152:18)
at fs.readFile (fs.js:176:14)
at Object.oncomplete (fs.js:297:15)
```

After pull request:

```
error.coffee:2:5: error: cannot pattern match over range loops
for {wat} in [1..10]
^^^^^
```

As you can see, the error message conforms to the format most compilers follow: `::: `, and includes the problematic error line plus a useful marker to see where we screwed up.

And it works for lexer, parser and compiler errors! All with the same format. The consistent format should help both humans and development tools to find where the errors are in the code :smiley_cat:

----

This pull request still needs some love though. These are some of the things that i plan to do in the upcoming days:

* Fix a bug in the parser error messages. The wrong token is being marked (one before from the one that should be marked).
* Implement some way to show multi-line errors. Any ideas on this?
* :sparkles: Colored output :sparkles:
* Integrate this into the on-line compiler at coffeescript.org. Haven't event though about this yet. Maybe now that we have more information about the errors we can display them differently. @michaelficarra do you know if Ace has some in-line error reporting feature?
* Integrate it in the REPL.
* More thorough testing. There're probably lots of edge cases that i'm missing.

----

But anyway, i wanted to open the pull request ASAP to see if it would be a welcomed change, and maybe gather some feedback/constructive criticism. Cheers!