Skip to content

Async finally swallows errors when it contains an await wrapped by try/except #23602

Closed
@nitely

Description

@nitely

Description

The following code should fail with an AssertionDefect error, but it does not.

import std/asyncdispatch

proc errval {.async.} =
  raise newException(ValueError, "err")
  
proc err {.async.} =
  try:
    doAssert false
  finally:
    echo "finally"
    # removing the following code will propagate the AssertionDefect
    try:
      await errval()
    except ValueError:
      echo "valueError"

proc main {.async.} =
  let errFut = err()
  await errFut

waitFor main()

Nim Version

Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-05-11
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: c91b33a
active boot switches: -d:release

Current Output

finally
valueError

Expected Output

finally
valueError
[AssertionDefect]

Possible Solution

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    AsyncEverything related to Nim's async

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions