Skip to content

Commit

Permalink
fix error when API was called with unregistered module name (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsidnev authored Jun 20, 2023
1 parent bb2e416 commit 265840c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- decoding a single propery for `EdgeDB.Object` that equals to an empty set.
- not catching an `EdgeDB.Error` exception during parameters encoding,
which caused throwing an exception for non-`!` functions.
- silent error for calling `EdgeDB` API with wrong module names.

### Removed

Expand Down
8 changes: 5 additions & 3 deletions lib/edgedb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,11 @@ defmodule EdgeDB do
end

defp to_client(client_name) when is_atom(client_name) do
client_name
|> Process.whereis()
|> to_client()
if pid = Process.whereis(client_name) do
to_client(pid)
else
raise EdgeDB.InterfaceError.new("could not find process associated with #{client_name}")
end
end

# ensure that client is really registered
Expand Down
5 changes: 5 additions & 0 deletions lib/edgedb/borrower.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ defmodule EdgeDB.Borrower do
end

@spec ensure_unborrowed!(EdgeDB.client()) :: :ok | no_return()

def ensure_unborrowed!(client) when is_pid(client) do
:ok
end

def ensure_unborrowed!(client) do
case GenServer.call(__MODULE__, {:check_borrowed, client}) do
:unborrowed ->
Expand Down
9 changes: 9 additions & 0 deletions test/edgedb/api_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -563,4 +563,13 @@ defmodule Tests.EdgeDB.APITest do
assert object[:user_type][:name] == "default::User"
end
end

test "EdgeDB API raises an error for wrong module name as a client" do
e =
assert_raise EdgeDB.Error, fn ->
EdgeDB.query!(EdgeDBWrongName, "select 'Hello world'")
end

assert %EdgeDB.Error{type: EdgeDB.InterfaceError} = e
end
end

0 comments on commit 265840c

Please sign in to comment.