第 6 行中未闭合的 INDENT ( CoffeeScript ) 编译器错误

发布于 2024-10-19 05:05:13 字数 1463 浏览 3 评论 0原文

这是我在 CoffeeScript 中的代码,用于使用 MongoDB 进行简单测试。 当我跑步时
咖啡-c UserDataProvider.coffee
我最终得到一个错误 UNCLOSED INDENT ON LINE 6

这是我的代码:

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)

StackTrace 是:

Error: In UserDataProvider.coffee, unclosed INDENT 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)

任何人都可以帮忙吗?

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 INDENT 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱要勇敢去追 2024-10-26 05:05:13

该行的第一个左括号永远不会关闭:

this.db.collection('data',(error,data) ->

实际上根本不需要它,因此如果您的目的是将“data”作为第一个参数传递,并且 function(error , data) { ... } 作为第二个参数。

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.

寂寞花火° 2024-10-26 05:05:13

仅供参考,无用的错误消息是当前版本中的错误。

FYI, the unhelpful error message is a bug in current version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文