spear
spear copied to clipboard
`Spear.append` with `raw?: true` does not do what docs say?
Context
The docs for Spear.append
state the following
:raw?
- (default:false
) a boolean which controls whether the return signature should be a simple:ok | {:error, any()}
or{:ok, AppendResp.t()} | {:error, any()}
. This can be used to extract metadata and information from the append response which is not available through the simplified return API, such as the stream's revision number after writing the events.
Issue
With that opts set it still returns :ok
iex(1)> Spear.append([Spear.Event.new("mytest", %{})], conn, "mytest3030300303349494", raw?: true)
:ok
iex(2)> Spear.append([Spear.Event.new("mytest", %{})], conn, "mytest333349494")
:ok
Thus, cannot use the feature to determine append response stream positions, etc.
Tracking down to the code:
https://github.com/NFIBrokerage/spear/blob/a08dfa90d210ded99dbe5dbcbc9e0fc0f3af0996/lib/spear.ex#L386
Stream append has the case function:
case request(
conn,
Streams,
:Append,
messages,
Keyword.take(opts, [:credentials, :timeout])
) do
{:ok, Streams.append_resp(result: {:success, _})} ->
:ok
{:ok, Streams.append_resp(result: {:wrong_expected_version, expectation_violation})} ->
{:error, Spear.Writing.map_expectation_violation(expectation_violation)}
error ->
error
end
end
That always masks the response by only returning :ok
.
Good catch! Would you like to submit a PR to fix it?
Fixed in #97