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)

データ ファイルには次の 1 行のみが含まれます。

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 に答える