Skip to content

Protocol fixes#37

Merged
frerich merged 7 commits into
mainfrom
protocol-fixes
May 17, 2026
Merged

Protocol fixes#37
frerich merged 7 commits into
mainfrom
protocol-fixes

Conversation

@frerich
Copy link
Copy Markdown
Owner

@frerich frerich commented May 17, 2026

No description provided.

frerich added 7 commits May 17, 2026 20:01
The collector function in the Collectable implementation for LargeObject
discarded the return value of LargeObject.write/2, causing write failures
(e.g. :read_only, :not_found) to go unnoticed and data to be silently lost.

Now raises a RuntimeError with a descriptive message when write fails.
The collector function discarded the return value of LargeObject.close/1
on the :done signal. If close failed (e.g. object already closed or
deleted), the error was swallowed silently.

Now raises a RuntimeError with a descriptive message when close fails.
The next_fun in Stream.resource only pattern-matched {:ok, ""} and
{:ok, data} from read/2. If read returned {:error, reason} (e.g. object
deleted mid-stream), it crashed with an unhelpful CaseClauseError.

Now raises a descriptive RuntimeError on read failure. Also makes the
after_fun resilient to close failures during cleanup.
When size/1 failed, the with block fell through returning {:error, :not_found}
which is not a valid Enumerable.count/1 return value. The protocol requires
{:ok, count} or {:error, module}.

Now explicitly returns {:error, __MODULE__} on failure.
The slice function used {:ok, size} = count(lob) which crashed with a
MatchError if the object was invalid. Now returns {:error, __MODULE__}
per the Enumerable protocol contract when count fails.
The slicing function (returned by slice/1) discarded the return value of
seek/3 for step=1, causing reads from wrong positions on failure. For both
step values, read errors would crash with MatchError.

Now raises descriptive RuntimeErrors on seek or read failures.
Credo complained that the `slice/1` implementation was getting a little
complex, and I tend to agree. Let's factory some code out into a
separate helper function.
@frerich frerich merged commit c31421e into main May 17, 2026
4 checks passed
@frerich frerich deleted the protocol-fixes branch May 17, 2026 20:02
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.

1 participant