Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Connection closed error creates case clause exception #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dylan-chong
Copy link

When Scylla dies while a query is in progress, we get a CaseClauseError where the unmatched value is {{"INSERT INTO events_v4 (...) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", %{...}}, {:error, :connection_closed}}. I've added a new case clause at the failing point to create an CQEx.Error appropriately.

I've tested that this works by commenting out some code in the library, replicating the issue, and fixing it

# lib/cqex/query.ex
  def call(c, q) do
    client = nil#CQEx.Client.get(c)

    # case q do
      # %CQEx.Query{statement: statement, values: values} when is_binary(statement) ->
        # {{statement, values}, :cqerl.run_query(client, convert(q))}

      # %CQEx.Query{} ->
        # :cqerl.run_query(client, convert(q))

      # any ->
        # :cqerl.run_query(client, any)
    # end
    {{"INSERT INTO events_v4 (...) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", %{}}, {:error, :connection_closed}}
    |> case do
      {_, {:ok, result}} ->
        {:ok, CQEx.Result.convert(result, client)}

      {:ok, result} ->
        {:ok, CQEx.Result.convert(result, client)}

      {:error, {:error, {reason, stacktrace}}} ->
        {:error, %{msg: ":cqerl processing error: #{reason}", acc: stacktrace}}

      {{s, v}, {:error, {code, message, _extras}}} ->
        {:error,
         %{msg: "#{message} (Code #{code})\nStatement: #{s}\nValues: #{inspect(v)}", acc: []}}

      {{s, v}, {:error, e}} ->
        {:error,
         %{msg: "#{inspect(e)} \nStatement: #{s}\nValues: #{inspect(v)}", acc: []}}

      {:error, {code, message, _extras}} ->
        {:error, %{msg: "#{message} (Code #{code})", acc: []}}
    end
  end

Test by running

recompile; CQEx.Query.call(nil, nil)
#  also
recompile; CQEx.Query.call!(nil, nil)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant