Skip to content

Commit 1c1498f

Browse files
authored
Cast all error reasons to String (#242)
Error reasons are sent as atoms from the NIF side
1 parent a00d643 commit 1c1498f

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/exqlite/basic.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule Exqlite.Basic do
1616
def close(%Connection{} = conn) do
1717
case Sqlite3.close(conn.db) do
1818
:ok -> :ok
19-
{:error, reason} -> {:error, %Error{message: reason}}
19+
{:error, reason} -> {:error, %Error{message: to_string(reason)}}
2020
end
2121
end
2222

@@ -30,7 +30,7 @@ defmodule Exqlite.Basic do
3030
{:ok, rows, columns}
3131

3232
{:error, %Error{message: message}, %Connection{}} ->
33-
{:error, message}
33+
{:error, to_string(message)}
3434
end
3535
end
3636

lib/exqlite/connection.ex

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ defmodule Exqlite.Connection do
166166
def disconnect(_err, %__MODULE__{db: db}) do
167167
case Sqlite3.close(db) do
168168
:ok -> :ok
169-
{:error, reason} -> {:error, %Error{message: reason}}
169+
{:error, reason} -> {:error, %Error{message: to_string(reason)}}
170170
end
171171
end
172172

@@ -321,7 +321,7 @@ defmodule Exqlite.Connection do
321321
{:cont, %Result{rows: rows, command: :fetch, num_rows: chunk_size}, state}
322322

323323
{:error, reason} ->
324-
{:error, %Error{message: reason, statement: statement}, state}
324+
{:error, %Error{message: to_string(reason), statement: statement}, state}
325325

326326
:busy ->
327327
{:error, %Error{message: "Database is busy", statement: statement}, state}
@@ -493,7 +493,7 @@ defmodule Exqlite.Connection do
493493
{:ok, state}
494494
else
495495
{:error, reason} ->
496-
{:error, %Exqlite.Error{message: reason}}
496+
{:error, %Exqlite.Error{message: to_string(reason)}}
497497
end
498498
end
499499

@@ -514,7 +514,7 @@ defmodule Exqlite.Connection do
514514
{:ok, query}
515515
else
516516
{:error, reason} ->
517-
{:error, %Error{message: reason, statement: statement}, state}
517+
{:error, %Error{message: to_string(reason), statement: statement}, state}
518518
end
519519
end
520520

@@ -527,7 +527,7 @@ defmodule Exqlite.Connection do
527527
{:ok, %{query | ref: ref}}
528528

529529
{:error, reason} ->
530-
{:error, %Error{message: reason, statement: statement}, state}
530+
{:error, %Error{message: to_string(reason), statement: statement}, state}
531531
end
532532
end
533533

@@ -590,7 +590,7 @@ defmodule Exqlite.Connection do
590590
{:ok, query}
591591

592592
{:error, reason} ->
593-
{:error, %Error{message: reason, statement: statement}, state}
593+
{:error, %Error{message: to_string(reason), statement: statement}, state}
594594
end
595595
end
596596

@@ -600,7 +600,7 @@ defmodule Exqlite.Connection do
600600
{:ok, columns}
601601

602602
{:error, reason} ->
603-
{:error, %Error{message: reason, statement: statement}, state}
603+
{:error, %Error{message: to_string(reason), statement: statement}, state}
604604
end
605605
end
606606

@@ -610,7 +610,7 @@ defmodule Exqlite.Connection do
610610
{:ok, rows}
611611

612612
{:error, reason} ->
613-
{:error, %Error{message: reason, statement: statement}, state}
613+
{:error, %Error{message: to_string(reason), statement: statement}, state}
614614
end
615615
end
616616

@@ -627,7 +627,7 @@ defmodule Exqlite.Connection do
627627
{:ok, result, %{state | transaction_status: transaction_status}}
628628
else
629629
{:error, reason} ->
630-
{:disconnect, %Error{message: reason, statement: statement}, state}
630+
{:disconnect, %Error{message: to_string(reason), statement: statement}, state}
631631
end
632632
end
633633

0 commit comments

Comments
 (0)