scala / scala/scala-java8-compat

Future.recover does not catch exceptions that are thrown inside a CompletableFuture

Open
#169 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
438
Forks
63
Avg merge
5h 12m
Merged PRs (30d)
2

Description

I've been using the aws dynamodb async sdk, but I find that I cannot catch exceptions after I convert a CompletableFuture to Scala.
When I run

    client
      .createTable(tableSchema.createTableRequest(tableName))
      .thenApply[Unit](_ => Unit)
      .exceptionally {
        case _: Throwable => // exception is now property handled
      }

I can successfully catch the exception.

However when I run

     import scala.compat.java8.FutureConverters.toScala

    val cf = client
      .createTable(tableSchema.createTableRequest(tableName))
    toScala(cf).recover {
      case _: Throwable => // never gets executed
    }

I cannot actually catch the exception. Any clues on why?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with scala.compat.java8.FutureConverters.toScala and compare its exception behavior with CompletableFuture.exceptionally using the examples in the issue. Trace how exceptions from the CompletableFuture are propagated, then verify that Future.recover handles them as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, scala
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.