Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Gracefully exit instead of crashing when a file is not found. #144

Merged
merged 3 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Autoencoder/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func readFile(_ filename: String) -> [UInt8] {
let d = Python.open(filePath, "rb").read()
return Array(numpy: np.frombuffer(d, dtype: np.uint8))!
}
fatalError(
"Failed to find file with name \(filename) in the following folders: \(possibleFolders).")
print("Failed to find file with name \(filename) in the following folders: \(possibleFolders).")
exit(-1)
}

/// Reads MNIST images and labels from specified file paths.
Expand Down
3 changes: 2 additions & 1 deletion MNIST/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func readFile(_ path: String) -> [UInt8] {
let data = try! Data(contentsOf: filePath, options: [])
return [UInt8](data)
}
fatalError("Filename not found: \(path)")
print("File not found: \(path)")
exit(-1)
}

/// Reads MNIST images and labels from specified file paths.
Expand Down
5 changes: 4 additions & 1 deletion MiniGo/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ let modelConfig = ModelConfiguration(boardSize: boardSize)
var model = GoModel(configuration: modelConfig)

guard FileManager.default.fileExists(atPath: "./MiniGoCheckpoint/000939-heron.data-00000-of-00001")
else { fatalError("Please download the MiniGo checkpoint according to the README.md.") }
else {
print("Please download the MiniGo checkpoint according to the README.md.")
exit(-1)
}
let reader = PythonCheckpointReader(path: "./MiniGoCheckpoint/000939-heron")
model.load(from: reader)

Expand Down