Skip to content

Support module plugs with options in pipe_through#6755

Open
RicardoSantos-99 wants to merge 1 commit into
phoenixframework:mainfrom
RicardoSantos-99:fix/6711-pipe-through-module-plug
Open

Support module plugs with options in pipe_through#6755
RicardoSantos-99 wants to merge 1 commit into
phoenixframework:mainfrom
RicardoSantos-99:fix/6711-pipe-through-module-plug

Conversation

@RicardoSantos-99

Copy link
Copy Markdown

Closes #6711.

Using a module plug with options as a {plug, opts} tuple in pipe_through
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 bare module plug) worked, but a {plug, opts}
tuple was passed through as the plug itself, which Plug.Builder then tried
to 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_through metadata (used by telemetry/logging) may now
contain a {plug, opts} tuple in addition to atoms. Happy to adjust if you'd
prefer that field to stay atoms-only.

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
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.

pipe_through with module plug and options doesn't compile

1 participant