Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send_frame should not call exit, but send_frame! should #86

Open
focused opened this issue Jul 23, 2020 · 0 comments
Open

send_frame should not call exit, but send_frame! should #86

focused opened this issue Jul 23, 2020 · 0 comments

Comments

@focused
Copy link

focused commented Jul 23, 2020

I have a gen server that calls other module with Websockex.send_frame, sometimes send_frame exits and parent gen server process exits too, so the only way I can handle it is to use try/catch :exit.

The spec of send_frame tells us that it returns result tuple, but it can exit in abnormal situation. I think there should be two variants: send_frame - never exits and returns :ok/:error, send_frame! - returns or exits.

@spec send_frame(client, frame) ::

@spec send_frame(client, frame) ::
          :ok
          | {:error,
             %WebSockex.FrameEncodeError{}
             | %WebSockex.ConnError{}
             | %WebSockex.NotConnectedError{}
             | %WebSockex.InvalidFrameError{}}
          | none
  def send_frame(client, _) when client == self() do
    raise %WebSockex.CallingSelfError{function: :send_frame}
  end

  def send_frame(client, frame) do
    try do
      {:ok, res} = :gen.call(client, :"$websockex_send", frame)
      res
    catch
      _, reason ->
        exit({reason, {__MODULE__, :call, [client, frame]}})
    end
  end
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

No branches or pull requests

1 participant