Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Auth] Remove unnecessary throws on internal methods #14154

Merged
merged 2 commits into from
Nov 20, 2024
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
6 changes: 3 additions & 3 deletions FirebaseAuth/Sources/Swift/Storage/AuthUserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AuthUserDefaults {
storage = UserDefaults()
}

func data(forKey key: String) throws -> Data? {
func data(forKey key: String) -> Data? {
guard let allData = storage.persistentDomain(forName: persistentDomainName)
else { return nil }
if let data = allData[key] as? Data {
Expand All @@ -44,13 +44,13 @@ class AuthUserDefaults {
return nil
}

func setData(_ data: Data, forKey key: String) throws {
func setData(_ data: Data, forKey key: String) {
var allData = storage.persistentDomain(forName: persistentDomainName) ?? [:]
allData[key] = data
storage.setPersistentDomain(allData, forName: persistentDomainName)
}

func removeData(forKey key: String) throws {
func removeData(forKey key: String) {
guard var allData = storage.persistentDomain(forName: persistentDomainName) else { return }
allData.removeValue(forKey: key)
storage.setPersistentDomain(allData, forName: persistentDomainName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AuthStoredUserManager {
/// Get the user access group stored locally.
/// - Returns: The stored user access group; otherwise, `nil`.
func getStoredUserAccessGroup() -> String? {
if let data = try? userDefaults.data(forKey: Self.storedUserAccessGroupKey) {
if let data = userDefaults.data(forKey: Self.storedUserAccessGroupKey) {
let userAccessGroup = String(data: data, encoding: .utf8)
return userAccessGroup
} else {
Expand All @@ -55,9 +55,9 @@ class AuthStoredUserManager {
/// - Parameter accessGroup: The access group to be store.
func setStoredUserAccessGroup(accessGroup: String?) {
if let data = accessGroup?.data(using: .utf8) {
try? userDefaults.setData(data, forKey: Self.storedUserAccessGroupKey)
userDefaults.setData(data, forKey: Self.storedUserAccessGroupKey)
} else {
try? userDefaults.removeData(forKey: Self.storedUserAccessGroupKey)
userDefaults.removeData(forKey: Self.storedUserAccessGroupKey)
}
}

Expand Down
8 changes: 4 additions & 4 deletions FirebaseAuth/Tests/Unit/AuthUserDefaultsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class AuthUserDefaultsTests: XCTestCase {
@brief Tests reading non-existing storage item.
*/
func testReadNonexisting() throws {
XCTAssertNil(try storage.data(forKey: kKey))
XCTAssertNil(storage.data(forKey: kKey))
}

/** @fn testWriteRead
@brief Tests writing and reading a storage item.
*/
func testWriteRead() throws {
try storage.setData(dataFromString(kData), forKey: kKey)
XCTAssertEqual(try storage.data(forKey: kKey), try dataFromString(kData))
XCTAssertEqual(storage.data(forKey: kKey), try dataFromString(kData))
}

/** @fn testOverwrite
Expand All @@ -50,7 +50,7 @@ class AuthUserDefaultsTests: XCTestCase {
let kOtherData = "OTHER_DATA"
try storage.setData(dataFromString(kData), forKey: kKey)
try storage.setData(dataFromString(kOtherData), forKey: kKey)
XCTAssertEqual(try storage.data(forKey: kKey), try dataFromString(kOtherData))
XCTAssertEqual(storage.data(forKey: kKey), try dataFromString(kOtherData))
}

/** @fn testRemove
Expand All @@ -67,7 +67,7 @@ class AuthUserDefaultsTests: XCTestCase {
func testServices() throws {
try storage.setData(dataFromString(kData), forKey: kKey)
storage = AuthUserDefaults(service: "Other service")
XCTAssertNil(try storage.data(forKey: kKey))
XCTAssertNil(storage.data(forKey: kKey))
}

/** @fn testStandardUserDefaults
Expand Down
Loading