我试图在我的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