Importing: Show OS error when unable to open a .conf file

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2019-02-24 16:50:57 +05:30
parent d3df8734c2
commit ab6d714070
1 changed files with 8 additions and 2 deletions

View File

@ -28,8 +28,14 @@ class TunnelImporter {
let fileContents: String let fileContents: String
do { do {
fileContents = try String(contentsOf: url) fileContents = try String(contentsOf: url)
} catch { } catch let error {
errorPresenterType.showErrorAlert(title: tr("alertCantOpenInputConfFileTitle"), message: tr(format: "alertCantOpenInputConfFileMessage (%@)", fileName), from: sourceVC, onPresented: completionHandler) let message: String
if let cocoaError = error as? CocoaError, cocoaError.isFileError {
message = error.localizedDescription
} else {
message = tr(format: "alertCantOpenInputConfFileMessage (%@)", fileName)
}
errorPresenterType.showErrorAlert(title: tr("alertCantOpenInputConfFileTitle"), message: message, from: sourceVC, onPresented: completionHandler)
return return
} }
if let tunnelConfiguration = try? TunnelConfiguration(fromWgQuickConfig: fileContents, called: fileBaseName) { if let tunnelConfiguration = try? TunnelConfiguration(fromWgQuickConfig: fileContents, called: fileBaseName) {