Protocol fixes#37
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.