Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use local function scrub_params/1 inside Endpoint #408

Closed
dmorneau opened this issue Jul 8, 2020 · 1 comment · Fixed by #410
Closed

Can't use local function scrub_params/1 inside Endpoint #408

dmorneau opened this issue Jul 8, 2020 · 1 comment · Fixed by #410

Comments

@dmorneau
Copy link

dmorneau commented Jul 8, 2020

Environment

  • Elixir version (elixir -v): 1.10.4
  • Erlang/OTP version (erl): 23
  • Sentry version (mix deps): 8.0.0-rc2
  • Operating system: macOS
  • Is this an umbrella application?: no
  • Release type (Distillery, mix release, Mix, etc.): mix release

Description

This sample code from the 8.0.0-rc2 doc causes a compile error if I try to use it in my app:

use Sentry.PlugContext, body_scrubber: &scrub_params/1

...even though there is a scrub_params/1 function defined within the module. This used to work fine when using Sentry.Plug within the Router, with locally defined functions.

Expected Behavior

If I define a local function inside the Endpoint module, then pass it to Sentry.PlugContext, I would expect it to compile fine.

Actual Behavior

== Compilation error in file lib/myapp_web/endpoint.ex ==
** (CompileError) lib/myapp_web/endpoint.ex:68: undefined function scrub_params/1
    (stdlib 3.13) lists.erl:1354: :lists.mapfoldl/3
    (stdlib 3.13) lists.erl:1355: :lists.mapfoldl/3
    (stdlib 3.13) lists.erl:1354: :lists.mapfoldl/3
    (stdlib 3.13) lists.erl:1355: :lists.mapfoldl/3
    (stdlib 3.13) lists.erl:1354: :lists.mapfoldl/3
    (stdlib 3.13) lists.erl:1355: :lists.mapfoldl/3
    (elixir 1.10.4) expanding macro: Kernel.@/1
    lib/myapp_web/endpoint.ex:66: MyAppWeb.Endpoint (module)
    (plug 1.10.3) expanding macro: Plug.Builder.plug/2

Steps to Reproduce

In a Phoenix app, define this function inside the endpoint module:

  def scrub_params(conn) do
    Enum.into(conn.params, %{})
    |> Map.drop(["secret"])
  end

Then somewhere else in the endpoint use it in PlugContext:

  plug Sentry.PlugContext, body_scrubber: &scrub_params/1

It doesn't matter if the function is defined before or after the plug.

Workaround

Using a tuple works:

  plug Sentry.PlugContext, body_scrubber: {__MODULE__, :scrub_params}
@mitchellhenke
Copy link
Contributor

Thanks for reporting. I've updated and re-published the docs for rc2 and plan on doing a general release next week 🙂

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 a pull request may close this issue.

2 participants