Return an exception struct from put_locale_from_session/2 for an empty session - #20
Merged
Merged
Conversation
…y session
The spec and the 1.1.0 changelog say {:error, Exception.t()}, and an
invalid session locale already returns a struct, but a session without
a locale still returned a {module, message} tuple.
UnknownLocaleError only carries a locale id, so its message for an empty session was "The locale nil is not known.".
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.
Before
Problem
{:error, Exception.t()}, and the 1.1.0 changelog says this function now reports errors as exception structs. The empty-session branch was missed.Exception.message/1or a%{__exception__: true}match fails on this one branch.### Returnsdoc still describes{:error, {exception, reason}}.After
Details
Cause: the fallback clause of
Localize.Plug.put_locale_from_session/2inlib/localize/plug.ex.Design: a small
Localize.Plug.NoSessionLocaleError, defined inLocalize.Plug, keeps the existing message.Localize.UnknownLocaleError, which the tuple named, has only a:locale_idfield and would print "The locale nil is not known."; no exception inlocalizetakes a free message. The### Returnsdoc now says{:error, exception}and names this case, and the module is listed in the Plugs docs group.Tests: the existing empty-session test in
test/localize_web_test.exsnow matches%Localize.Plug.NoSessionLocaleError{}and checks its message; it fails onmain.Checks:
mix test(267 passed),mix format --check-formatted,mix compile --warnings-as-errors.mix credo --strictreports only the existingSigil_q.InterpolationTestmodule-name issue.AI disclosure: AI models helped us find this issue, write the change, and review it.