A small service builds a text preview response from a computation result and, when needed, uses a fallback text. Right now, in one scenario the summary is incomplete: the error from the input Future does not reach the calling code, and with partially empty data the result is chosen without waiting for the completed computation.
ResponsePreview.render accepts:
fallback: => Stringvalue: Future[Option[String]]ec: ExecutionContextFuture[String].value completes successfully and contains a non-empty string after trim, return it.value completes successfully, but the string is missing or empty after trim, use fallback.value fails, return the failed Future without replacing the error with fallback text.fallback must not be evaluated ahead of time if it is not needed.Future.import scala.concurrent.*
import scala.concurrent.duration.*
import scala.util.*
given ExecutionContext = ExecutionContext.global
Future.successful(Some(" OK ")) gives "OK".Future.successful(Some(" ")) gives fallback text.Future.failed(new RuntimeException("boom")) remains unsuccessful.scala-cli test / ordinary project compilation without additional dependenciesExecutionContext.global for examples and testsUse line comments to explain the problem, its impact, the fix and how to test it.