fix: fail instead of throw when a transform on a completed FastFuture throws - #1305
Merged
Merged
Conversation
… throws Motivation: `FastFuture.successful` / `FastFuture.failed` return already completed futures that override `Future.transform` to apply the function directly. Unlike `DefaultPromise`, that override did not catch exceptions thrown by the function, so the standard `filter`, `collect` and `transform` combinators on such a future threw synchronously at the call site instead of returning a failed future. Callers cannot tell a FastFuture-produced `Future` from any other, and pekko-grpc now returns them from its public APIs. Modification: Route both `transform` overrides through a helper that converts a `NonFatal` exception from the function into an `ErrorFuture`, matching the contract of `Future.transform`. Result: Standard combinators on a completed FastFuture return a failed future when their function throws, the same as for `Future.successful` / `Future.failed`. Tests: - sbt "http-core/Test/testOnly org.apache.pekko.http.scaladsl.util.FastFutureSpec" - new transform/filter/collect cases fail without the fix, 32/32 pass with it - sbt "http-core/mimaReportBinaryIssues" - no issues (against 1.0.0) - scalafmt --mode diff-ref=upstream/main - git diff --check References: None - found while reviewing FastFuture stack and exception semantics for pekko-grpc
Philippus
approved these changes
Sep 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
FastFuture.successful/FastFuture.failedreturn already completed futures that overrideFuture.transformto apply the function directly instead of scheduling it. UnlikeDefaultPromise, that override did not catch exceptions thrown by the function, so the standardfilter,collectandtransformcombinators on such a future threw synchronously at the call site instead of returning a failed future:Callers cannot tell a FastFuture-produced
Futurefrom any other, and pekko-grpc now returns them from its public APIs (apache/pekko-grpc#686, apache/pekko-grpc#863), so user code combining those futures hit the difference.mapwas unaffected becauseTry.mapalready catches.Modification
Route the
transformoverrides ofFulfilledFutureandErrorFuturethrough a private helper that converts aNonFatalexception thrown by the function into anErrorFuture, matching the contract ofFuture.transform. Both classes are private, so no binary shape changes.Result
Standard combinators on a completed FastFuture return a failed future when their function throws, the same as for
Future.successful/Future.failed.Tests
sbt "http-core/Test/testOnly org.apache.pekko.http.scaladsl.util.FastFutureSpec"- the newtransform/filter/collectcases fail without the fix (4 failures), 32/32 pass with itsbt "http-core/mimaReportBinaryIssues"- no issues (compared against 1.0.0)scalafmt --mode diff-ref=upstream/maingit diff --checkReferences
None - found while reviewing FastFuture stack and exception semantics for pekko-grpc's increased use of it