How to debug interactively with dbg() in IEx without corrupting the return value?

I’m trying to debug interactively with Kernel.dbg/0 in IEx. But when I step through the code with n (next) or continue, this ultimately changes my function return value. What am I doing wrong?

Sample code:

defmodule DebugTest do
  use ExUnit.Case

  describe "test debug" do
    test "test a pipeline with dbg()" do
      assert double_add([1, 2, 3, 4]) == 20
    end
  end

  defp double_add(numbers) do
    numbers
    |> Enum.map(&(&1 * 2))
    |> Enum.reduce(&+/2)
    |> dbg()
  end
end

When I run this with iex -S mix test test/debug_test.exs, execution is halted, dbg does its work and prints each pipeline step, but after leaving the double_add function (with next or continue), my test fails:

  1) test test debug test a pipeline with dbg() (DebugTest)
     test/debug_test.exs:5
     Assertion with == failed
     code:  assert double_add([1, 2, 3, 4]) == 20
     left:  :ok
     right: 20
     stacktrace:
       test/debug_test.exs:6: (test)

Using dbg changed the function return value to :ok.

When I use IEx.pry() instead of dbg(), this doesn’t happen, but of course I don’t get the niceties of dbg anymore:

  defp double_add(numbers) do
    require IEx
    IEx.pry()

    numbers
    |> Enum.map(&(&1 * 2))
    |> Enum.reduce(&+/2)
  end

How is dbg() meant to be used interactively?

I’ve seen this too, but I’m not sure it’s intentional. It seems to be related to the pipe.

iex(1)> dbg hd([1,2,3])
Break reached: iex:1
pry(1)> next
hd([1, 2, 3]) #=> 1

1

vs

iex(1)> dbg [1,2,3] |> hd
Break reached: iex:1
pry(1)> next
[1, 2, 3] |> hd #=> 1

[:ok]