diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d2eb9ed..d216c465 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/edgedb.ex b/lib/edgedb.ex index de6f8493..45fbbd91 100644 --- a/lib/edgedb.ex +++ b/lib/edgedb.ex @@ -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 diff --git a/lib/edgedb/borrower.ex b/lib/edgedb/borrower.ex index faca8338..d653d44f 100644 --- a/lib/edgedb/borrower.ex +++ b/lib/edgedb/borrower.ex @@ -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 -> diff --git a/test/edgedb/api_test.exs b/test/edgedb/api_test.exs index 168dc231..250ddaf7 100644 --- a/test/edgedb/api_test.exs +++ b/test/edgedb/api_test.exs @@ -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