jashkenas/coffee-script — Issue #2144: Unhelpful/misleading Parse error Unexpected '{' when source has bad indents
Author: dkamins
Created: 2012-02-26 22:25:01+00:00
State: open

This was originally filed as Issue #2141, but it actually has nothing to do with tabs, and that issue was closed amid argument about tabs vs. spaces. Moving on...

The actual issue is that in the presence of invalid indents (e.g. see example below), the parser error **Unexpected '{'** is confusing, misleading, and incorrect. In this trivial example, it's easy to see what's wrong, but in a larger file with actual "{" chars, and especially for users new to CoffeeScript syntax, the error is very misleading.

Surely there is a more friendly error message such as "Unexpected Indent" or something similar that would be more appropriate than blaming the user for typing a character that doesn't even exist.

```coffeescript
foo:
spaces: 2
spaces: 4
```

```
Error: In test.coffee, Parse error on line 3: Unexpected '{'
at Object.parseError (/opt/local/lib/node_modules/coffee-script/lib/coffee-script/parser.js:470:11)
at Object.parse (/opt/local/lib/node_modules/coffee-script/lib/coffee-script/parser.js:546:22)
at Object.compile (/opt/local/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:40:22)
at /opt/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:140:33
at /opt/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:110:18
at [object Object]. (fs.js:115:5)
at [object Object].emit (events.js:64:17)
at afterRead (fs.js:1112:12)
at Object.wrapper [as oncomplete] (fs.js:254:17)
```