diff --git a/.swiftlint.yml b/.swiftlint.yml index 3b22ba8f7043..3fb4c3dc40e5 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -114,6 +114,9 @@ only_rules: # Closure arguments don't need to be wrapped in parentheses. - unneeded_parentheses_in_closure_argument + # Catch statements should not declare error variables without type casting. + - untyped_error_in_catch + # Unused parameter in a closure should be replaced with _. - unused_closure_parameter diff --git a/Modules/Sources/WordPressKit/DomainsServiceRemote+AllDomains.swift b/Modules/Sources/WordPressKit/DomainsServiceRemote+AllDomains.swift index f275784f254a..fa5d450432d8 100644 --- a/Modules/Sources/WordPressKit/DomainsServiceRemote+AllDomains.swift +++ b/Modules/Sources/WordPressKit/DomainsServiceRemote+AllDomains.swift @@ -16,7 +16,7 @@ extension DomainsServiceRemote { do { parameters = try queryParameters(from: params) - } catch let error { + } catch { completion(.failure(error)) return } diff --git a/Modules/Sources/WordPressKit/FeatureFlagRemote.swift b/Modules/Sources/WordPressKit/FeatureFlagRemote.swift index 108184d21144..75c84a3745d7 100644 --- a/Modules/Sources/WordPressKit/FeatureFlagRemote.swift +++ b/Modules/Sources/WordPressKit/FeatureFlagRemote.swift @@ -18,7 +18,7 @@ open class FeatureFlagRemote: ServiceRemoteWordPressComREST { do { dictionary = try params.dictionaryRepresentation() - } catch let error { + } catch { callback(.failure(error)) return } diff --git a/Modules/Sources/WordPressKit/PlanServiceRemote_ApiVersion1_3.swift b/Modules/Sources/WordPressKit/PlanServiceRemote_ApiVersion1_3.swift index ca5b4b93d999..bcc706504099 100644 --- a/Modules/Sources/WordPressKit/PlanServiceRemote_ApiVersion1_3.swift +++ b/Modules/Sources/WordPressKit/PlanServiceRemote_ApiVersion1_3.swift @@ -49,7 +49,7 @@ import WordPressKitObjC if decodedResult.isCurrentPlan { currentlyActivePlan = decodedResult } - } catch let error { + } catch { WPKitLogError("Error parsing plans response for site \(error)") } } diff --git a/Modules/Sources/WordPressKit/SiteDesignServiceRemote.swift b/Modules/Sources/WordPressKit/SiteDesignServiceRemote.swift index 94245d8f38f8..bc58bf1facb4 100644 --- a/Modules/Sources/WordPressKit/SiteDesignServiceRemote.swift +++ b/Modules/Sources/WordPressKit/SiteDesignServiceRemote.swift @@ -46,7 +46,7 @@ public class SiteDesignServiceRemote { do { let result = try parseLayouts(fromResponse: responseObject) completion(.success(result)) - } catch let error { + } catch { NSLog("error response object: %@", String(describing: responseObject)) completion(.failure(error)) } diff --git a/Sources/WordPressData/Swift/BlockedAuthor.swift b/Sources/WordPressData/Swift/BlockedAuthor.swift index 66022858b8a4..f3604655648d 100644 --- a/Sources/WordPressData/Swift/BlockedAuthor.swift +++ b/Sources/WordPressData/Swift/BlockedAuthor.swift @@ -23,7 +23,7 @@ public extension BlockedAuthor { request.predicate = query.predicate let result = try context.fetch(request) return result - } catch let error { + } catch { DDLogError("Couldn't fetch blocked author with error: \(error.localizedDescription)") return [] } diff --git a/Sources/WordPressData/Swift/BlockedSite.swift b/Sources/WordPressData/Swift/BlockedSite.swift index 8719de98e630..460cd1a51030 100644 --- a/Sources/WordPressData/Swift/BlockedSite.swift +++ b/Sources/WordPressData/Swift/BlockedSite.swift @@ -24,7 +24,7 @@ public extension BlockedSite { request.predicate = NSPredicate(format: "\(#keyPath(BlockedSite.accountID)) = %@ AND \(#keyPath(BlockedSite.blogID)) = %@", accountID, blogID) let result = try context.fetch(request) return result - } catch let error { + } catch { DDLogError("Couldn't fetch blocked site with error: \(error.localizedDescription)") return [] } diff --git a/WordPress/Classes/Jetpack/JetpackMigration/Common/MigrationEmailService.swift b/WordPress/Classes/Jetpack/JetpackMigration/Common/MigrationEmailService.swift index b76739cb7caf..61d006339d14 100644 --- a/WordPress/Classes/Jetpack/JetpackMigration/Common/MigrationEmailService.swift +++ b/WordPress/Classes/Jetpack/JetpackMigration/Common/MigrationEmailService.swift @@ -28,7 +28,7 @@ final class MigrationEmailService { throw MigrationError.accountNotFound } self.init(api: account.wordPressComRestV2Api) - } catch let error { + } catch { DDLogError("[\(MigrationError.domain)] Object instantiation failed: \(error.localizedDescription)") throw error } @@ -44,7 +44,7 @@ final class MigrationEmailService { throw MigrationError.unsuccessfulResponse } tracker.track(.emailSent) - } catch let error { + } catch { let properties = ["error_type": error.localizedDescription] tracker.track(.emailFailed, properties: properties) DDLogError("[\(MigrationError.domain)] Migration email sending failed: \(error.localizedDescription)") @@ -60,7 +60,7 @@ final class MigrationEmailService { let data = try JSONSerialization.data(withJSONObject: responseObject) let response = try decoder.decode(SendMigrationEmailResponse.self, from: data) continuation.resume(returning: response) - } catch let error { + } catch { continuation.resume(throwing: error) } } failure: { error, _ in diff --git a/WordPress/Classes/Services/ReaderCardService.swift b/WordPress/Classes/Services/ReaderCardService.swift index b5010036b124..a8735eb26e12 100644 --- a/WordPress/Classes/Services/ReaderCardService.swift +++ b/WordPress/Classes/Services/ReaderCardService.swift @@ -150,7 +150,7 @@ class ReaderCardService { guard let objectData = object as? NSManagedObject else { continue } context.delete(objectData) } - } catch let error { + } catch { print("Clean card error:", error) } } diff --git a/WordPress/Classes/Services/ReaderPostStreamService.swift b/WordPress/Classes/Services/ReaderPostStreamService.swift index 0a985dca4ab1..1988beb77cc5 100644 --- a/WordPress/Classes/Services/ReaderPostStreamService.swift +++ b/WordPress/Classes/Services/ReaderPostStreamService.swift @@ -79,7 +79,7 @@ class ReaderPostStreamService { } context.delete(post) } - } catch let error { + } catch { print("Clean post error:", error) } } diff --git a/WordPress/Classes/Utility/BackgroundTasks/WeeklyRoundupBackgroundTask.swift b/WordPress/Classes/Utility/BackgroundTasks/WeeklyRoundupBackgroundTask.swift index 9aa96bbf66d9..41084973833f 100644 --- a/WordPress/Classes/Utility/BackgroundTasks/WeeklyRoundupBackgroundTask.swift +++ b/WordPress/Classes/Utility/BackgroundTasks/WeeklyRoundupBackgroundTask.swift @@ -86,7 +86,7 @@ private class WeeklyRoundupDataProvider { do { service = try Self.makeRemoteStatsService(for: site) - } catch let error { + } catch { self.onError(error) continue } diff --git a/WordPress/Classes/Utility/ZendeskUtils.swift b/WordPress/Classes/Utility/ZendeskUtils.swift index d88332f1e177..da8dacc51726 100644 --- a/WordPress/Classes/Utility/ZendeskUtils.swift +++ b/WordPress/Classes/Utility/ZendeskUtils.swift @@ -746,8 +746,8 @@ private extension ZendeskUtils { let eventLogging = EventLogging(dataSource: dataProvider, delegate: delegate) try eventLogging.enqueueLogForUpload(log: logFile) } - catch let err { - return "Error preparing log file: \(err.localizedDescription)" + catch { + return "Error preparing log file: \(error.localizedDescription)" } return logFile.uuid diff --git a/WordPress/Classes/ViewRelated/Me/App Settings/EncryptedLogTableViewController.swift b/WordPress/Classes/ViewRelated/Me/App Settings/EncryptedLogTableViewController.swift index 138148c1f5b3..455a120d3831 100644 --- a/WordPress/Classes/ViewRelated/Me/App Settings/EncryptedLogTableViewController.swift +++ b/WordPress/Classes/ViewRelated/Me/App Settings/EncryptedLogTableViewController.swift @@ -109,8 +109,8 @@ class EncryptedLogTableViewController: UITableViewController { try self.eventLogging.enqueueLogForUpload(log: LogFile(url: url)) } - catch let err { - let alert = UIAlertController(title: "Unable to create log", message: err.localizedDescription, preferredStyle: .actionSheet) + catch { + let alert = UIAlertController(title: "Unable to create log", message: error.localizedDescription, preferredStyle: .actionSheet) self.present(alert, animated: true) } } diff --git a/WordPress/Classes/ViewRelated/Me/Me Main/MeViewController.swift b/WordPress/Classes/ViewRelated/Me/Me Main/MeViewController.swift index 07fc13526d32..9373a49960e0 100644 --- a/WordPress/Classes/ViewRelated/Me/Me Main/MeViewController.swift +++ b/WordPress/Classes/ViewRelated/Me/Me Main/MeViewController.swift @@ -462,7 +462,7 @@ public class MeViewController: UITableViewController { async let refreshSettings: Void = Self.refreshAccountSettings(with: accountSettingsService) let _ = try await [refreshDetails, refreshSettings] self.reloadViewModel() - } catch let error { + } catch { DDLogError("\(error.localizedDescription)") } } diff --git a/WordPress/Classes/ViewRelated/NUX/Controllers/Social Signup/SignupEpilogueViewController.swift b/WordPress/Classes/ViewRelated/NUX/Controllers/Social Signup/SignupEpilogueViewController.swift index a38017655950..710dddc5f9ba 100644 --- a/WordPress/Classes/ViewRelated/NUX/Controllers/Social Signup/SignupEpilogueViewController.swift +++ b/WordPress/Classes/ViewRelated/NUX/Controllers/Social Signup/SignupEpilogueViewController.swift @@ -268,8 +268,8 @@ private extension SignupEpilogueViewController { finished(success, error) } - } catch let err { - finished(false, err) + } catch { + finished(false, error) return } } diff --git a/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderPostActions/ReaderBlockUserAction.swift b/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderPostActions/ReaderBlockUserAction.swift index 128a2e5926a8..34fc44a9ea3f 100644 --- a/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderPostActions/ReaderBlockUserAction.swift +++ b/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderPostActions/ReaderBlockUserAction.swift @@ -13,7 +13,7 @@ final class ReaderBlockUserAction { do { let account = try WPAccount.lookupDefaultWordPressComAccount(in: context) return account - } catch let error { + } catch { DDLogError("Couldn't fetch default account: \(error.localizedDescription)") return nil } @@ -45,7 +45,7 @@ final class ReaderBlockUserAction { try context.save() self.trackEvent(authorID: authorID, blocked: blocked) completion?(.success(())) - } catch let error { + } catch { let operation = blocked ? "block" : "unblock" DDLogError("Couldn't \(operation) author: \(error.localizedDescription)") completion?(.failure(error)) diff --git a/WordPress/WordPressScreenshotGeneration/SnapshotHelper.swift b/WordPress/WordPressScreenshotGeneration/SnapshotHelper.swift index 634ad284f320..bd3222866ba6 100644 --- a/WordPress/WordPressScreenshotGeneration/SnapshotHelper.swift +++ b/WordPress/WordPressScreenshotGeneration/SnapshotHelper.swift @@ -74,7 +74,7 @@ open class Snapshot: NSObject { setLanguage(app) setLocale(app) setLaunchArguments(app) - } catch let error { + } catch { NSLog(error.localizedDescription) } } @@ -188,7 +188,7 @@ open class Snapshot: NSObject { #else try image.pngData()?.write(to: path, options: .atomic) #endif - } catch let error { + } catch { NSLog("Problem writing screenshot: \(name) to \(screenshotsDir)/\(simulator)-\(name).png") NSLog(error.localizedDescription) }