                 return
         }
 
-        let noItems = try keychain.allPersistentTokens()
-        XCTAssert(noItems.isEmpty, "Array should be empty: \(noItems)")
-
-        let savedItem1 = try keychain.addToken(token1)
-        let savedItem2 = try keychain.addToken(token2)
-        let savedItem3 = try keychain.addToken(token3)
-
-        let allItems = try keychain.allPersistentTokens()
-
-        XCTAssertNotNil(itemFromArray(allItems, withPersistentRef: savedItem1.identifier),
-            "Token not recovered from keychain: \(token1)")
-        XCTAssertNotNil(itemFromArray(allItems, withPersistentRef: savedItem2.identifier),
-            "Token not recovered from keychain: \(token2)")
-        XCTAssertNotNil(itemFromArray(allItems, withPersistentRef: savedItem3.identifier),
-            "Token not recovered from keychain: \(token3)")
+        do {
+            let noItems = try keychain.allPersistentTokens()
+            XCTAssert(noItems.isEmpty, "Array should be empty: \(noItems)")
+        } catch {
+            XCTFail("Error thrown from keychain: \(error)")
+            return
+        }
+
+        guard let savedItem1 = try? keychain.addToken(token1),
+            let savedItem2 = try? keychain.addToken(token2),
+            let savedItem3 = try? keychain.addToken(token3) else {
+                XCTFail("Failed to save tokens")
+                return
+        }
+
+        do {
+            let allItems = try keychain.allPersistentTokens()
+            XCTAssertNotNil(itemFromArray(allItems, withPersistentRef: savedItem1.identifier),
+                "Token not recovered from keychain: \(token1)")
+            XCTAssertNotNil(itemFromArray(allItems, withPersistentRef: savedItem2.identifier),
+                "Token not recovered from keychain: \(token2)")
+            XCTAssertNotNil(itemFromArray(allItems, withPersistentRef: savedItem3.identifier),
+                "Token not recovered from keychain: \(token3)")
+        } catch {
+            XCTFail("Error thrown from keychain: \(error)")
+            return
+        }
 
         do {
             try keychain.deletePersistentToken(savedItem1)

            return
        }

        let itemsRemaining = try keychain.allPersistentTokens()

        XCTAssertNil(itemFromArray(itemsRemaining, withPersistentRef: savedItem1.identifier),
            "Token not removed from keychain: \(token1)")
        XCTAssertNil(itemFromArray(itemsRemaining, withPersistentRef: savedItem2.identifier),
            "Token not removed from keychain: \(token2)")
        XCTAssertNil(itemFromArray(itemsRemaining, withPersistentRef: savedItem3.identifier),
            "Token not removed from keychain: \(token3)")
    } catch {
        XCTFail("Error thrown from keychain: \(error)")
        return
    }
    }
}

    }

    func testAllTokensInKeychain() {
        guard let token1 = Token.URLSerializer.deserialize(kValidTokenURL),
            let token2 = Token.URLSerializer.deserialize(kValidTokenURL),
            let token3 = Token.URLSerializer.deserialize(kValidTokenURL) else {
