         } else if string == kFactorTimerKey {
             let period = try queryDictionary[kQueryPeriodKey].map(parseTimerPeriod) ?? defaultPeriod
             return .timer(period: period)
-        }
-        throw DeserializationError.factor
+        } else {
+            throw DeserializationError.invalidFactor(string)
+        }
     }
 
     let algorithm = try queryDictionary[kQueryAlgorithmKey].map(algorithmFromString) ?? defaultAlgorithm


private func parseCounterValue(_ rawValue: String) throws -> UInt64 {
    guard let counterValue = UInt64(rawValue, radix: 10) else {
        throw DeserializationError.counterValue
    }
    return counterValue
}

private func parseTimerPeriod(_ rawValue: String) throws -> TimeInterval {
    guard let int = Int(rawValue) else {
        throw DeserializationError.timerPeriod
    }
    return TimeInterval(int)
}

private func parseSecret(_ rawValue: String) throws -> Data {
    guard let data = MF_Base32Codec.data(fromBase32String: rawValue) else {
        throw DeserializationError.secret
    }
    return data
}

private func parseDigits(_ rawValue: String) throws -> Int {
    guard let intValue = Int(rawValue) else {
        throw DeserializationError.digits
    }
    return intValue
}

}

internal enum DeserializationError: Swift.Error {
    case invalidFactor(String)
    case invalidCounterValue(String)
    case invalidTimerPeriod(String)
    case invalidSecret(String)
    case invalidAlgorithm(String)
    case invalidDigits(String)
}

private let defaultAlgorithm: Generator.Algorithm = .sha1
