diff --git a/SwiftShell/File.swift b/SwiftShell/File.swift index 1cc51f0..2df5d96 100644 --- a/SwiftShell/File.swift +++ b/SwiftShell/File.swift @@ -64,8 +64,12 @@ public func open(path: String, mode: FileMode = .Read) -> File { } // file may be nil if for instance path is invalid - // TODO: it physically pains me to write the next line. Proper error handling is forthcoming. - assert( file != nil, "open file \"\(path)\" failed.") + // TODO: it physically pains me to write the next lines. Proper error handling is forthcoming. + if file == nil { + standarderror.write("Error: Opening file \"\(path)\" failed.\n") + exit(EXIT_FAILURE) + } + return file! } diff --git a/SwiftShellTests/Scripts/exitswhenopeningnon-existentfile.swift b/SwiftShellTests/Scripts/exitswhenopeningnon-existentfile.swift new file mode 100644 index 0000000..20481d2 --- /dev/null +++ b/SwiftShellTests/Scripts/exitswhenopeningnon-existentfile.swift @@ -0,0 +1,5 @@ + +import SwiftShell + +let file = open("file which does not exist") +print("this is not printed, the script has exited")