Unclosed INDENT in line 6 ( CoffeeScript ) Compiler Error
Here is my code in CoffeeScript for a simple test with MongoDB. When I run
coffee -c UserDataProvider.coffee
I end up with an error UNCLOSED INDENT ON LINE 6
This is my code:
Db = require('mongodb/db').Db
ObjectID = require('mongodb/bson/bson').ObjectID
Server = require('mongodb/connection').Server
class UserDataProvider
constructor = (host,port)->
this.db = new Db( 'test' , new Server(host ,port,{}))
getCollection = (callback) ->
this.db.collection('data',(error,data)->
if error then callback(error)
else callback(data)
The StackTrace is:
Error: In UserDataProvider.coffee, unclosed IN开发者_如何学运维DENT on line 6
at Error (unknown source)
at Rewriter.ensureBalance (/usr/local/lib/node/.npm/coffee-script/1.0.1/package/lib/rewriter.js:283:17)
at Rewriter.rewrite (/usr/local/lib/node/.npm/coffee-script/1.0.1/package/lib/rewriter.js:21:12)
at Lexer.tokenize (/usr/local/lib/node/.npm/coffee-script/1.0.1/package/lib/lexer.js:37:29)
at Object.compile (/usr/local/lib/node/.npm/coffee-script/1.0.1/package/lib/coffee-script.js:26:34)
at /usr/local/lib/node/.npm/coffee-script/1.0.1/package/lib/command.js:117:33
at /usr/local/lib/node/.npm/coffee-script/1.0.1/package/lib/command.js:85:26
at [object Object].<anonymous> (fs.js:86:5)
at [object Object].emit (events.js:39:17)
at afterRead (fs.js:843:12)
Can anyone help?
The first left parenthesis on this line is never closed:
this.db.collection('data',(error,data) ->
It is actually not needed at all, so you probably want to remove it all together, if your intention is to pass "data" as the first argument and the function(error, data) { ... }
as the second argument.
FYI, the unhelpful error message is a bug in current version.
- https://github.com/jashkenas/coffee-script/issues/1120
精彩评论