0

当我对从文件读取的字符串使用 String.contains 方法时,我的 opa 应用程序失败:

import stdlib.io.file
import stdlib.core


function start()
{
        txt = string_of_binary(File.content("data.txt"))
        jlog(txt)
        b = String.contains(txt, "Rabbit")

        <>Hello Bug</>
}

Server.start(
   {port:8092, netmask:0.0.0.0, encryption: {no_encryption}, name:"bug"},
   [ {resources: @static_resource_directory("resources")},
     {register: {css: []} },
     {page: start, title: "bug"},
   ]
)

我有以下错误:

bug serving on http://ks3098156.kimsufi.com:8092
[Opa] Server dispatch Decoded URL to /
STDERR:rabbit


/home/kayhman/website/rstEditor/code/bug_depends/qmlCpsClientLib.js:26
_error = true;global.console.log("Uncaught exception : " + global.e.toString()
                                                                    ^
TypeError: Cannot call method 'toString' of undefined
    at /home/kayhman/website/rstEditor/code/bug_depends/qmlCpsClientLib.js:26:222
    at /home/kayhman/website/rstEditor/code/bug_depends/qmlCpsClientLib.js:27:78
    at /home/kayhman/website/rstEditor/code/bug_depends/qmlCpsClientLib.js:22:128
    at /home/kayhman/website/rstEditor/code/bug_depends/qmlCpsClientLib.js:28:263
    at dispatcher_cps (/home/kayhman/website/rstEditor/code/bug_depends/bslNet.nodejs:60:165)
    at Server.<anonymous> (/home/kayhman/website/rstEditor/code/bug_depends/bslNet.nodejs:59:437)
    at Server.emit (events.js:70:17)
    at HTTPParser.onIncoming (http.js:1514:12)
    at HTTPParser.onHeadersComplete (http.js:102:31)
    at Socket.ondata (http.js:1410:22)

数据文件只包含一行:

rabbit 

我的代码有什么问题?

谢谢

4

1 回答 1

1

File.content 确实有一个错误,它将在下一个版本中修复。您可以使用更可取的(和有效的)安全File.content_opt功能:

function start() {
        match(File.content_opt("data.txt")){
        case {none} :<>No file</>
        case {some:content} :
            txt = string_of_binary(content)
            jlog(txt)
            b = String.contains(txt, "Rabbit")
            <>Hello Bug</>
        }
}
于 2012-07-26T11:57:35.520 回答