我試圖在我的Swift 3.0.2(與3.0.1一起發生)服務器應用程序在Heroku上運行它(它在Ubuntu上運行它)中嘗試調用String(contentsOfFile:encoding:)
,但函數中止程序。顯示在heroku logs
以下錯誤:String(contentsOfFile:encoding :)以退出狀態中止139
2016-12-26T01:59:01.304535+00:00 heroku[web.1]: Process exited with status 139
有比其它任何錯誤消息。我試圖讀取的文件與應用程序的源文件位於同一目錄樹中。下面是實際的代碼的功能上等同的收縮(在main.swift
頂層):
let sqlDirectory = URL(fileURLWithPath: #file).deletingLastPathComponent().path + "/Models/SQL/"
do {
print("reading")
fflush(stdout)
let a = try String(contentsOfFile: sqlDirectory + "createTables.sql", encoding: .utf8)
print("done")
fflush(stdout)
} catch {
print("error")
fflush(stdout)
}
的sqlDirectory
的運行時間值是/tmp/build_514c5587b46ef976e60d4f039b4d048d/Sources/App/Models/SQL/
(散列是在每個構建不同)。它在打印reading
後崩潰。 done
或error
從不打印。 (標準輸出刷新僅用於調試,以確保所有內容都寫入標準輸出。刪除它們不會影響崩潰。)
這是怎麼回事?我該如何解決?
我也報告過這個錯誤here,因爲它似乎這可能是一個錯誤。
狀態139是'段錯誤'(SIGSEGV)。 – user28434
'String(contentsOfFile:encoding:)'拋出,你在do/try/catch上下文中調用它嗎?你如何指定文件名和路徑?你傳遞給該呼叫的是什麼編碼?我對Heroku並不熟悉,但源文件的位置可能不是該進程的當前工作目錄。 –
@MartinR修改了問題的細節。 – emlai