From 8515f1dfb1e3f9a98a582975ad1dd7d555c000a1 Mon Sep 17 00:00:00 2001 From: Benjamin Maer Date: Fri, 19 Apr 2019 13:56:38 -0400 Subject: [PATCH 1/2] We no longer catch an error just to throw it again. --- Sources/Disk+InternalHelpers.swift | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Sources/Disk+InternalHelpers.swift b/Sources/Disk+InternalHelpers.swift index 68661af..8c7c214 100644 --- a/Sources/Disk+InternalHelpers.swift +++ b/Sources/Disk+InternalHelpers.swift @@ -100,20 +100,16 @@ extension Disk { /// Find an existing file's URL or throw an error if it doesn't exist static func getExistingFileURL(for path: String?, in directory: Directory) throws -> URL { - do { - let url = try createURL(for: path, in: directory) - if FileManager.default.fileExists(atPath: url.path) { - return url - } + let url: URL = try createURL(for: path, in: directory) + guard FileManager.default.fileExists(atPath: url.path) else { throw createError( .noFileFound, description: "Could not find an existing file or folder at \(url.path).", failureReason: "There is no existing file or folder at \(url.path)", recoverySuggestion: "Check if a file or folder exists before trying to commit an operation on it." ) - } catch { - throw error } + return url } /// Convert a user generated name to a valid file name From 3e41a599b6bb9132d667d09aa510cef43aa99d4a Mon Sep 17 00:00:00 2001 From: Benjamin Maer Date: Mon, 22 Apr 2019 10:46:28 -0400 Subject: [PATCH 2/2] Removed unnecessary type declaration --- Sources/Disk+InternalHelpers.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Disk+InternalHelpers.swift b/Sources/Disk+InternalHelpers.swift index 8c7c214..26d719b 100644 --- a/Sources/Disk+InternalHelpers.swift +++ b/Sources/Disk+InternalHelpers.swift @@ -100,7 +100,7 @@ extension Disk { /// Find an existing file's URL or throw an error if it doesn't exist static func getExistingFileURL(for path: String?, in directory: Directory) throws -> URL { - let url: URL = try createURL(for: path, in: directory) + let url = try createURL(for: path, in: directory) guard FileManager.default.fileExists(atPath: url.path) else { throw createError( .noFileFound,