Problems on the "with" statement, please help!


I have a feeling that his would very stupid question, but I really can’t understand where is the problem.

I have the following code extract:
    with    {:ok, user_id}     <- UserAuthentication.get_user_id(guest),
    {:ok, user_name}   <- UserAuthentication.get_user_name(guest),
    {:ok, user_avatar} <- UserAuthentication.get_user_avatar(guest)
    user = %{id: user_id, name: user_name, avatar: user_avatar}


def get_user_id(%AuthenticationStruct{} = auth_struct) do
    { :ok, auth_struct.uid }

auth_struct.uid - is just a binary string

When I run the above code the following error.
# no with clause matching: "Bim Bom"

The questions is why there is no match ?
why it is trying to match only string ? When the function get_user_id returns {ok, id } ?

You should show your UserAuthentication.get_user_name() function.

I guess it does return the name, and not the tuple {:ok, name}, that would be why there is no match.


Hm… I felt that this is a stupid question :man_facepalming:
The debugger highlighted the line with get_user_id and I started to dig this function without looking on get_user_name. Problem solved.

1 Like

There is no stupid question, just answer can be stupid :slight_smile:


But, without that answer I would spend too match time on checking wrong thing.
Thank you very much for your help :+1: