@@ -5,18 +5,20 @@ import zio.stream._
55import zio .openfeature .internal .{ClientEvaluator , ContextConverter , ErrorCodeConverter , FeatureFlagsState }
66import dev .openfeature .sdk .{
77 Client => OFClient ,
8- FeatureProvider => OFFeatureProvider ,
9- FlagEvaluationDetails ,
10- Reason => OFReason ,
118 ErrorCode => OFErrorCode ,
12- OpenFeatureAPI ,
13- MutableTrackingEventDetails ,
9+ FeatureProvider => OFFeatureProvider ,
10+ FlagValueType => JavaFlagValueType ,
11+ HookContext => JavaHookContext ,
1412 ProviderEvent => JavaProviderEvent ,
13+ Reason => OFReason ,
1514 EventDetails ,
16- FlagValueType => JavaFlagValueType ,
17- HookContext => JavaHookContext
15+ FlagEvaluationDetails ,
16+ MutableTrackingEventDetails ,
17+ OpenFeatureAPI
1818}
19+
1920import scala .jdk .CollectionConverters ._
21+ import scala .util .control .NonFatal
2022
2123final private [openfeature] class FeatureFlagsLive (
2224 client : OFClient ,
@@ -47,7 +49,9 @@ final private[openfeature] class FeatureFlagsLive(
4749 val javaMeta = details.getEventMetadata
4850 if (javaMeta == null || javaMeta.isEmpty) FlagMetadata .empty
4951 else convertImmutableMetadata(javaMeta)
50- } catch { case _ : Exception => FlagMetadata .empty }
52+ } catch {
53+ case _ : Exception => FlagMetadata .empty
54+ }
5155
5256 val readyHandler : java.util.function.Consumer [EventDetails ] = details =>
5357 Unsafe .unsafe { implicit u =>
@@ -195,7 +199,7 @@ final private[openfeature] class FeatureFlagsLive(
195199 case ProviderStatus .Fatal => ZIO .fail(FeatureFlagError .ProviderFatal )
196200 case ProviderStatus .NotReady => ZIO .fail(FeatureFlagError .ProviderNotReady (ProviderStatus .NotReady ))
197201 case ProviderStatus .Error => ZIO .fail(FeatureFlagError .ProviderNotReady (ProviderStatus .Error ))
198- case _ => ZIO .unit
202+ case _ => Exit .unit
199203 }
200204
201205 // Context is already merged by evaluateWithDetails before entering the hook pipeline
@@ -609,7 +613,7 @@ final private[openfeature] class FeatureFlagsLive(
609613 override def currentEvaluatedFlags : UIO [Map [String , zio.openfeature.FlagEvaluation [_]]] =
610614 state.transactionRef.get.flatMap {
611615 case Some (ts) => ts.getEvaluations
612- case None => ZIO .succeed(Map .empty)
616+ case None => Exit .succeed(Map .empty)
613617 }
614618
615619 override def events : ZStream [Any , Nothing , ProviderEvent ] =
@@ -715,13 +719,16 @@ final private[openfeature] class FeatureFlagsLive(
715719
716720 private def getProviderHooks : UIO [List [FeatureHook ]] =
717721 providerRef.get.flatMap { p =>
718- ZIO
719- .attempt {
720- val javaHooks = p.getProviderHooks
722+ try {
723+ val javaHooks = p.getProviderHooks
724+ val res =
721725 if (javaHooks == null || javaHooks.isEmpty) Nil
722726 else javaHooks.asScala.toList.map(wrapJavaHook)
723- }
724- .catchAll(e => ZIO .logWarning(s " Failed to get provider hooks: ${e.getMessage}" ).as(Nil ))
727+ Exit .succeed(res)
728+ } catch {
729+ case NonFatal (e) =>
730+ ZIO .logWarningCause(s " Failed to get provider hooks " , Cause .fail(e)).as(Nil )
731+ }
725732 }
726733
727734 @ scala.annotation.nowarn(" msg=deprecated" )
@@ -766,17 +773,17 @@ final private[openfeature] class FeatureFlagsLive(
766773 val hook = javaHook.asInstanceOf [dev.openfeature.sdk.Hook [Any ]]
767774 new FeatureHook {
768775 override def before (ctx : HookContext , hints : HookHints ): UIO [Option [(EvaluationContext , HookHints )]] =
769- ZIO
770- .attempt {
776+ ZIO .succeed {
777+ try {
771778 val jCtx = toJavaHookContext(ctx)
772779 val jHints = hints.values.map { case (k, v) => k -> v.asInstanceOf [Object ] }.asJava
773780 val result = hook.before(jCtx, jHints)
774781 if (result != null && result.isPresent) {
775782 val newCtx = fromJavaEvaluationContext(result.get())
776783 Some ((newCtx, hints))
777784 } else None
778- }
779- .catchAll(_ => ZIO .none)
785+ } catch { case NonFatal (_) => None }
786+ }
780787
781788 override def after [A ](ctx : HookContext , details : FlagResolution [A ], hints : HookHints ): UIO [Unit ] =
782789 ZIO .attempt {
@@ -846,15 +853,13 @@ final private[openfeature] class FeatureFlagsLive(
846853 // Shutdown API (spec 1.6.1, 1.6.2)
847854
848855 override def shutdown : UIO [Unit ] =
849- ZIO .collectAllParDiscard(
850- List (
851- state.statusRef.set(ProviderStatus .NotReady ),
852- state.hooksRef.set(List .empty),
853- state.globalContextRef.set(EvaluationContext .empty),
854- state.clientContextRef.set(EvaluationContext .empty),
855- state.trackRecorder.set(List .empty)
856- )
857- ) *> state.eventHub.shutdown *> ZIO .attemptBlocking(api.shutdown()).ignore
856+ state.statusRef.set(ProviderStatus .NotReady ) *>
857+ state.hooksRef.set(List .empty) *>
858+ state.globalContextRef.set(EvaluationContext .empty) *>
859+ state.clientContextRef.set(EvaluationContext .empty) *>
860+ state.trackRecorder.set(List .empty) *>
861+ state.eventHub.shutdown *>
862+ ZIO .attemptBlocking(api.shutdown()).ignore
858863
859864 // Tracking API
860865
0 commit comments