Skip to content

Conversation

@nathanl
Copy link
Contributor

@nathanl nathanl commented Oct 28, 2025

This is helpful if the application has more than one repo (eg read replicas). For example:

Before: ** (DBConnection.ConnectionError) connection is closed because of an error, disconnect or timeout

After: ** (DBConnection.ConnectionError) MyApp.Repo connection is closed because of an error, disconnect or timeout

Before: ** (DBConnection.OwnershipError) cannot find ownership process for #PID<0.1128.0> ({Phoenix.LiveView, MyAppWeb.FooLive, "lv:phx-GHKljxU3bpZfbx9j"}) using mode :manual

After: ** (DBConnection.OwnershipError) cannot find ownership process for #PID<0.1128.0> ({Phoenix.LiveView, MyAppWeb.FooLive, "lv:phx-GHKljxU3bpZfbx9j"}) using mode :manual on repo MyApp.Repo

This is helpful if the application has more than one repo (eg read
replicas). For example:

Before: "** (DBConnection.ConnectionError) connection is closed because
of an error, disconnect or timeout"

After: "** (DBConnection.ConnectionError) MyApp.Repo connection is
closed because of an error, disconnect or timeout"
Retain repo name in the state of DBConnection.Ownership.Manager for the
sake of clearer errors.

Before: `** (DBConnection.OwnershipError) cannot find ownership process
for #PID<0.1128.0> ({Phoenix.LiveView,
MyAppWeb.FooLive, "lv:phx-GHKljxU3bpZfbx9j"})
using mode :manual`

After: `** (DBConnection.OwnershipError) cannot find ownership process
for #PID<0.1128.0> ({Phoenix.LiveView,
MyAppWeb.FooLive, "lv:phx-GHKljxU3bpZfbx9j"})
using mode :manual on repo MyApp.Repo`
using mode #{inspect(mode)}.
using mode #{inspect(mode)} on repo #{inspect(repo)}.
(Note that a connection's mode reverts to :manual if its owner
terminates.)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on line 381

@josevalim
Copy link
Member

Hi @nathanl. I would prefer to not depend on repo, because it is really not a db_connection configuration or concern. Can you find anything on Process.info(self()) or Process.info(self(), :registered_name) you could use?

@nathanl
Copy link
Contributor Author

nathanl commented Oct 30, 2025

@josevalim good point, but won't 99% of users pass a repo? In maybe_prefix_repo it's optional - would you be satisfied if it were optional everywhere in these messages?

@realglebivanov
Copy link
Contributor

@nathanl would you consider adding some libary-agnostic metadata(contained e.g. in a kw-list) to the exception a viable option?

@nathanl
Copy link
Contributor Author

nathanl commented Nov 3, 2025

@realglebivanov Can you elaborate a bit on what that might look like?

@realglebivanov
Copy link
Contributor

realglebivanov commented Nov 3, 2025

@realglebivanov Can you elaborate a bit on what that might look like?

So, right now DBConnection.ConnectionError contains only message, reason and severity.
Instead of modifying the existing message text, we could add an additional field to the DBConnection.ConnectionError that could contain useful metadata.
Also, in this case we wouldn't have to rely on specific option types, it could be just a keyword list.
Of course, that could cost us an overhead of storing and copying around the list.
Hopefully, I made my point clear.

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.

3 participants