** (Protocol.UndefinedError) protocol String.Chars not implemented for {:ok, %App.Accounts.User{

Hi there,

I am getting this error after I update information.

[error] #PID<0.1239.0> running AppWeb.Endpoint (connection #PID<0.1051.0>, stream id 10) terminated
Server: localhost:4000 (http)
Request: POST /graphiql
** (exit) an exception was raised:
    ** (Protocol.UndefinedError) protocol String.Chars not implemented for {:ok, %App.Accounts.User{__meta__: #Ecto.Schema.Metadata<:loaded, "users">, id: "337061ec-4438-4cea-91cc-d20637646026", first_name: "John", first_name_hash: <<2, 212, 40, 245, 74, 85, 161, 208, 10, 223, 126, 116, 1, 39, 94, 145, 6, 188, 74, 220, 191, 129, 168, 2, 36, 81, 31, 5, 106, 112, 20, 38>>, last_name: "Doe", last_name_hash: <<138, 38, 87, 124, 31, 176, 136, 55, 43, 37, 13, 53, 13, 215, 51, 141, 175, 81, 246, 142, 152, 55, 81, 62, 254, 25, 107, 192, 232, 21, 127, 255>>, username: "9h777yf", gender: "Male", dob: ~D[1970-01-01], email: "venkat@example.com", email_hash: <<226, 154, 65, 95, 52, 227, 165, 42, 151, 70, 133, 30, 188, 86, 112, 123, 75, 201, 41, 68, 240, 181, 170, 44, 171, 204, 117, 236, 26, 7, 89, 167>>, password_hash: "$pbkdf2-sha512$160000$bK1/jv6n8/raLMhXIzZfiQ$8iyNTdLKixVUZa3E2QJ30DZlkjOjGRrvwEpBOpXw3VoY6iWEtfmobvr5MIxvqBUuCoVAlplfwhRtj7FFpzUbew", password: nil, password_confirmation: nil, primary_phone: nil, primary_phone_hash: nil, alternate_phone: nil, alternate_phone_hash: nil, access_token: "gj3vchbpvb1p3be06h0w4f5v7ktbheah7kdx0m93ofhcfy2q4tqhenbeizlbd8mr0k1x9jfj4m78bl79uptj5goh1d9uwf2x77hh", email_token: "vvtq4yslc0ya7nz0yahl6cc95i3e2p", profile_completed: true, token: nil, terms: nil, country: "US", location: "27215", location_details: %{country_code: "US", country_name: "United States", latitude: 36.0318, longitude: -79.4889, place_name: "Burlington", postal_code: "27215", state_code: "NC", state_name: "North Carolina"}, current_sign_in_at: ~U[2023-08-04 15:43:38Z], last_sign_in_at: ~U[2023-08-04 15:19:50Z], sign_in_count: 13, current_sign_in_ip: nil, last_sign_in_ip: nil, daily_counter: 7, daily_counter_date: ~U[2023-07-23 05:28:20Z], confirmation_code: nil, inputed_code: nil, confirmed_at: ~U[2023-08-04 15:44:37Z], confirmation_sent_at: nil, conversations: #Ecto.Association.NotLoaded<association :conversations is not loaded>, interests: #Ecto.Association.NotLoaded<association :interests is not loaded>, profile: #Ecto.Association.NotLoaded<association :profile is not loaded>, preference: #Ecto.Association.NotLoaded<association :preference is not loaded>, inserted_at: ~N[2023-07-22 04:07:29], updated_at: ~N[2023-08-04 15:54:06]}} of type Tuple
        (elixir 1.15.2) lib/string/chars.ex:3: String.Chars.impl_for!/1
        (elixir 1.15.2) lib/string/chars.ex:22: String.Chars.to_string/1
        (elixir 1.15.2) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
        (absinthe 1.7.1) lib/absinthe/subscription/local.ex:90: Absinthe.Subscription.Local.do_get_docs/3
        (absinthe 1.7.1) lib/absinthe/subscription/local.ex:26: anonymous fn/4 in Absinthe.Subscription.Local.publish_mutation/3
        (elixir 1.15.2) lib/enum.ex:2510: Enum."-reduce/3-lists^foldl/2-0-"/3
        (absinthe 1.7.1) lib/absinthe/subscription/local.ex:25: Absinthe.Subscription.Local.publish_mutation/3
        (absinthe 1.7.1) lib/absinthe/subscription.ex:117: Absinthe.Subscription.publish/3
        (absinthe 1.7.1) lib/absinthe/subscription.ex:207: Absinthe.Subscription.call/2
        (absinthe 1.7.1) lib/absinthe/phase/document/execution/resolution.ex:232: Absinthe.Phase.Document.Execution.Resolution.reduce_resolution/1
        (absinthe 1.7.1) lib/absinthe/phase/document/execution/resolution.ex:187: Absinthe.Phase.Document.Execution.Resolution.do_resolve_field/3
        (absinthe 1.7.1) lib/absinthe/phase/document/execution/resolution.ex:172: Absinthe.Phase.Document.Execution.Resolution.do_resolve_fields/6
        (absinthe 1.7.1) lib/absinthe/phase/document/execution/resolution.ex:143: Absinthe.Phase.Document.Execution.Resolution.resolve_fields/4
        (absinthe 1.7.1) lib/absinthe/phase/document/execution/resolution.ex:88: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
        (absinthe 1.7.1) lib/absinthe/phase/document/execution/resolution.ex:67: Absinthe.Phase.Document.Execution.Resolution.perform_resolution/3
        (absinthe 1.7.1) lib/absinthe/phase/document/execution/resolution.ex:24: Absinthe.Phase.Document.Execution.Resolution.resolve_current/3
        (absinthe 1.7.1) lib/absinthe/pipeline.ex:405: Absinthe.Pipeline.run_phase/3
        (absinthe_plug 1.5.8) lib/absinthe/plug.ex:536: Absinthe.Plug.run_query/4
        (absinthe_plug 1.5.8) lib/absinthe/plug.ex:290: Absinthe.Plug.call/2
        (phoenix 1.6.16) lib/phoenix/router/route.ex:41: Phoenix.Router.Route.call/2

I am doing the following in my absinthe resolver

def update_user(_, args, %{context: context}) do
  user = context[:current_user]

  case Accounts.update_user(user, args) do
    {:error, changeset} ->
      {:error, ChangesetErrors.extract_error_msg(changeset)}

    {:ok, updated_user} ->
      {:ok, updated_user}
  end

I can’t figure out the issue. I have similar resolvers getting a user struct and they all work fine.

Appreciate help!

This error message is telling you that there is a call to Kernel.to_string/1 on something that can’t be converted to a string. {:ok, struct} cannot be converted to a string. Hence the error.

PS: Also please use Markdown code fences for your code examples. Use triple backticks like:

```elixir
defmodule Blah do

end
```

1 Like

This stacktrace suggests that you should check how your subscriptions are configured; somehow an {:ok, %Account{}} tuple is ending up where the subscription machinery expects a topic.

1 Like

Genius!.. It was indeed the subscription.

I fixed the subscription and it works.

Thank you!