Skip to content

Fix the compiler warnings, and the runtime bug hiding behind one - #5

Merged
dominicletz merged 2 commits into
witchtails:masterfrom
neutrino38:fix/compile-without-warnings
Nov 2, 2026
Merged

dominicletz merged 2 commits into
witchtails:masterfrom
neutrino38:fix/compile-without-warnings

Conversation

@neutrino38

Copy link
Copy Markdown

Three small fixes, so that mix compile --warnings-as-errors — which this
repository's CI already runs — passes again on recent Elixir. One of them is a
crash, not just a warning.

  • Socket.Helpers.bang/1 now does the :ok | {:ok, _} | {:error, _}
    unwrapping that defbang used to inline at each call site. Behind a function
    boundary, the compiler no longer flags dead clauses in Socket.TCP.accept!/1,
    accept!/2, Socket.Port.open!/1 and open!/2.

  • Socket.Web.accept/2 returns {:error, e.message} on a Socket.Error,
    matching what connect/3 already did. It used e.code, a key that exception
    does not have, so Socket.Web.accept(listener, timeout: 50) raised
    KeyError. A new test covers it.

  • Socket.Web.connect/3 drops its rescue on Socket.TCP.Error and
    Socket.SSL.Error. Neither module exists in this library, and those
    transports raise Socket.Error, which the clause above already catches.

No renaming, no reformatting, no other behaviour change.

Verified on Elixir 1.18.3 / OTP 26: mix format --check-formatted,
mix compile --warnings-as-errors, mix test (12 tests, 0 failures).

The macro inlined a three-clause `case` at every call site, so a wrapped
function with a narrower return type left a dead clause: Socket.TCP.accept!/1,
accept!/2, Socket.Port.open!/1 and open!/2 all warned. A macro cannot know
that return type; behind a function boundary every clause matches again.
`accept/2` answered `{:error, e.code}`, but Socket.Error defines only
:message, so the clause raises KeyError instead of returning a tuple:
`Socket.Web.accept(listener, timeout: 50)` dies on `key :code not found`.
`connect/3` already returns e.message.

`connect/3` also rescues Socket.TCP.Error and Socket.SSL.Error, defined
nowhere, so that clause can never match. Removed: those transports raise
Socket.Error, already caught above.
@dominicletz
dominicletz merged commit 8e03495 into witchtails:master Nov 2, 2026
4 checks passed
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.

2 participants