diff --git a/Sources/OpenFeature/FeatureProvider.swift b/Sources/OpenFeature/FeatureProvider.swift index 4191441..81ea221 100644 --- a/Sources/OpenFeature/FeatureProvider.swift +++ b/Sources/OpenFeature/FeatureProvider.swift @@ -6,10 +6,10 @@ public protocol FeatureProvider { var metadata: Metadata { get } // Called by OpenFeatureAPI whenever the new Provider is registered - func initialize(initialContext: EvaluationContext) async + func initialize(initialContext: EvaluationContext?) async // Called by OpenFeatureAPI whenever a new EvaluationContext is set by the application - func onContextSet(oldContext: EvaluationContext, newContext: EvaluationContext) async + func onContextSet(oldContext: EvaluationContext?, newContext: EvaluationContext) async func getBooleanEvaluation(key: String, defaultValue: Bool) throws -> ProviderEvaluation< Bool diff --git a/Sources/OpenFeature/NoOpProvider.swift b/Sources/OpenFeature/NoOpProvider.swift index 8e9fe58..3431e2d 100644 --- a/Sources/OpenFeature/NoOpProvider.swift +++ b/Sources/OpenFeature/NoOpProvider.swift @@ -6,11 +6,11 @@ class NoOpProvider: FeatureProvider { var metadata: Metadata = NoOpMetadata(name: "No-op provider") var hooks: [AnyHook] = [] - func onContextSet(oldContext: EvaluationContext, newContext: EvaluationContext) { + func onContextSet(oldContext: EvaluationContext?, newContext: EvaluationContext) { // no-op } - func initialize(initialContext: EvaluationContext) { + func initialize(initialContext: EvaluationContext?) { // no-op } diff --git a/Sources/OpenFeature/OpenFeatureAPI.swift b/Sources/OpenFeature/OpenFeatureAPI.swift index 103fc2b..9be13c2 100644 --- a/Sources/OpenFeature/OpenFeatureAPI.swift +++ b/Sources/OpenFeature/OpenFeatureAPI.swift @@ -4,7 +4,7 @@ import Foundation /// Configuration here will be shared across all ``Client``s. public class OpenFeatureAPI { private var _provider: FeatureProvider? - private var _context: EvaluationContext = MutableContext() + private var _context: EvaluationContext? private(set) var hooks: [AnyHook] = [] /// The ``OpenFeatureAPI`` singleton diff --git a/Sources/OpenFeature/exceptions/OpenFeatureError.swift b/Sources/OpenFeature/exceptions/OpenFeatureError.swift index a4ea9bf..c595f3a 100644 --- a/Sources/OpenFeature/exceptions/OpenFeatureError.swift +++ b/Sources/OpenFeature/exceptions/OpenFeatureError.swift @@ -8,6 +8,7 @@ public enum OpenFeatureError: Error, Equatable { case targetingKeyMissingError case typeMismatchError case valueNotConvertableError + case providerNotReadyError public func errorCode() -> ErrorCode { switch self { @@ -25,6 +26,8 @@ public enum OpenFeatureError: Error, Equatable { return .typeMismatch case .valueNotConvertableError: return .general + case .providerNotReadyError: + return .providerNotReady } } } @@ -46,6 +49,8 @@ extension OpenFeatureError: CustomStringConvertible { return "Type mismatch" case .valueNotConvertableError: return "Could not convert value" + case .providerNotReadyError: + return "The value was resolved before the provider was ready" } } } diff --git a/Tests/OpenFeatureTests/Helpers/AlwaysBrokenProvider.swift b/Tests/OpenFeatureTests/Helpers/AlwaysBrokenProvider.swift index c68f862..871d7d2 100644 --- a/Tests/OpenFeatureTests/Helpers/AlwaysBrokenProvider.swift +++ b/Tests/OpenFeatureTests/Helpers/AlwaysBrokenProvider.swift @@ -6,11 +6,11 @@ class AlwaysBrokenProvider: FeatureProvider { var metadata: Metadata = AlwaysBrokenMetadata() var hooks: [AnyHook] = [] - func onContextSet(oldContext: OpenFeature.EvaluationContext, newContext: OpenFeature.EvaluationContext) { + func onContextSet(oldContext: OpenFeature.EvaluationContext?, newContext: OpenFeature.EvaluationContext) { // no-op } - func initialize(initialContext: OpenFeature.EvaluationContext) { + func initialize(initialContext: OpenFeature.EvaluationContext?) { // no-op } diff --git a/Tests/OpenFeatureTests/Helpers/DoSomethingProvider.swift b/Tests/OpenFeatureTests/Helpers/DoSomethingProvider.swift index 72d1a3c..b67dca7 100644 --- a/Tests/OpenFeatureTests/Helpers/DoSomethingProvider.swift +++ b/Tests/OpenFeatureTests/Helpers/DoSomethingProvider.swift @@ -4,11 +4,11 @@ import OpenFeature class DoSomethingProvider: FeatureProvider { public static let name = "Something" - func onContextSet(oldContext: OpenFeature.EvaluationContext, newContext: OpenFeature.EvaluationContext) { + func onContextSet(oldContext: OpenFeature.EvaluationContext?, newContext: OpenFeature.EvaluationContext) { // no-op } - func initialize(initialContext: OpenFeature.EvaluationContext) { + func initialize(initialContext: OpenFeature.EvaluationContext?) { // no-op }