Skip to content

Use try/catch for non-blocking Java calls and log Cause#113

Closed
EtaCassiopeia wants to merge 1 commit into
mainfrom
perf/try-catch-non-blocking-calls
Closed

Use try/catch for non-blocking Java calls and log Cause#113
EtaCassiopeia wants to merge 1 commit into
mainfrom
perf/try-catch-non-blocking-calls

Conversation

@EtaCassiopeia
Copy link
Copy Markdown
Owner

@EtaCassiopeia EtaCassiopeia commented May 12, 2026

Summary

getProviderHooks and wrapJavaHook.before were wrapping Java SDK calls in ZIO.attempt(...).catchAll(...). ZIO.attempt creates a Sync node and catchAll adds a FlatMap node — two ZIO instances the runloop must interpret. Since the wrapped calls are non-blocking, in-memory Java methods, a plain try/catch + Exit.succeed (or ZIO.succeed { try { ... } catch ... }) achieves the same safety with fewer runloop iterations.

Also upgrades getProviderHooks error logging from ZIO.logWarning(s"... ${e.getMessage}") to ZIO.logWarningCause(...) so the full Cause (with stack trace) appears in diagnostics.

Changes

  • FeatureFlagsLive.getProviderHooksZIO.attempt + catchAlltry/catch + Exit.succeed; log Cause.fail(e) instead of just the message
  • FeatureFlagsLive.wrapJavaHook.beforeZIO.attempt + catchAll(_ => ZIO.none)ZIO.succeed { try { ... } catch { case NonFatal(_) => None } }

Both call sites assume NonFatal (preserves original Exception-catching behavior; VirtualMachineError/LinkageError propagate).

Credit

Spotted in #110 by @guizmaii. The logWarningCause upgrade is an addition; the original PR kept the message-only logging.

@EtaCassiopeia
Copy link
Copy Markdown
Owner Author

Tested independently; closing in favor of #110.

@EtaCassiopeia EtaCassiopeia deleted the perf/try-catch-non-blocking-calls branch May 13, 2026 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant