Support module plugs with options in pipe_through#6755
Open
RicardoSantos-99 wants to merge 1 commit into
Open
Conversation
A module plug given with options as a {plug, opts} tuple raised at
compile time:
pipe_through [:api, {MyPlug, greeting: "hey"}]
** (ArgumentError) errors were found at the given arguments:
* 1st argument: not an atom
build_pipes/2 mapped every entry to {plug, [], true}, so a bare atom
(function plug, pipeline, or module) worked, but a {plug, opts} tuple was
passed through as the plug itself, which Plug.Builder then tried to treat
as an atom. Map {plug, opts} tuples to {plug, opts, true} and keep the
existing behaviour for bare entries.
Closes phoenixframework#6711
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.
Closes #6711.
Using a module plug with options as a
{plug, opts}tuple inpipe_throughraised at compile time:
build_pipes/2mapped every entry to{plug, [], true}, so a bare atom(function plug, pipeline, or bare module plug) worked, but a
{plug, opts}tuple was passed through as the plug itself, which
Plug.Builderthen triedto treat as an atom. This maps
{plug, opts}tuples to{plug, opts, true}and keeps the existing behaviour for bare entries.
Added a test covering the mixed case (a pipeline plus a module plug with
options) and documented the form in
pipe_through/1.Note: the route's
pipe_throughmetadata (used by telemetry/logging) may nowcontain a
{plug, opts}tuple in addition to atoms. Happy to adjust if you'dprefer that field to stay atoms-only.