8000 send_frame should not call `exit`, but send_frame! should · Issue #86 · dominicletz/websockex · GitHub
[go: up one dir, main page]

Skip to content
8000

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

Open

Description

@focused

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.

https://github.com/Azolo/websockex/blob/ce7064e1d6e8dfb1bba1bb8d3e75b71b88aabc1e/lib/websockex.ex#L413

@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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0