Media Proxy Issue: FunctionClauseError

I can’t determine what is causing Media Proxy all of a sudden to fail. I was doing some admin adjustments to other items (I can’t remember, it was so long ago) but I didn’t restart the server. I was doing dependency updates to latest versions and when I re-started I was getting the errors below. I removed the mediaproxy configuration from the database so I could get it back up and running but would like to turn media proxy back on. Any pointers or advise welcome. Thanks.

FQDN TLD renamed to RFC:

16:46:00.553 [error] #PID<0.25942.0> running Pleroma.Web.Endpoint (connection #PID<0.25939.0>, stream id 1) terminated
Server: social.example.com:80 (http)
Request: GET /api/v1/timelines/public?local=true&only_media=false&with_muted=true&limit=20
** (exit) an exception was raised:
** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1
(elixir 1.17.3) lib/io.ex:696: IO.chardata_to_string(nil)
(elixir 1.17.3) lib/path.ex:681: Path.do_join/3
(elixir 1.17.3) lib/path.ex:673: Path.join/2
(elixir 1.17.3) lib/path.ex:641: Path.join/1
(pleroma 3.15.2) lib/pleroma/web/media_proxy.ex:82: Pleroma.Web.MediaProxy.whitelisted?/1
(pleroma 3.15.2) lib/pleroma/web/media_proxy.ex:55: Pleroma.Web.MediaProxy.url_proxiable?/1
(pleroma 3.15.2) lib/pleroma/web/media_proxy.ex:46: Pleroma.Web.MediaProxy.url/1
(pleroma 3.15.2) lib/pleroma/web/mastodon_api/views/status_view.ex:534: Pleroma.Web.MastodonAPI.StatusView.render/2

17:02:12.432 [error] Process #PID<0.5853.0> raised an exception
** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1
(elixir 1.17.3) lib/io.ex:696: IO.chardata_to_string(nil)
(elixir 1.17.3) lib/path.ex:681: Path.do_join/3
(elixir 1.17.3) lib/path.ex:673: Path.join/2
(elixir 1.17.3) lib/path.ex:641: Path.join/1
(pleroma 3.15.2) lib/pleroma/web/media_proxy.ex:82: Pleroma.Web.MediaProxy.whitelisted?/1
(pleroma 3.15.2) lib/pleroma/web/media_proxy.ex:55: Pleroma.Web.MediaProxy.url_proxiable?/1
(pleroma 3.15.2) lib/pleroma/web/media_proxy.ex:46: Pleroma.Web.MediaProxy.url/1
(pleroma 3.15.2) lib/pleroma/web/mastodon_api/views/status_view.ex:534: Pleroma.Web.MastodonAPI.StatusView.render/2

17:08:23.355 request_id=GFkbznMhcuS0cycAA2pi [error] Internal server error: %FunctionClauseError{module: IO, function: :chardata_to_string, arity: 1, kind: nil, args: nil, clauses: nil}

17:08:23.355 [error] #PID<0.6686.0> running Pleroma.Web.Endpoint (connection #PID<0.6685.0>, stream id 1) terminated
Server: social.example.com:80 (http)
Request: GET /api/v1/accounts/verify_credentials
** (exit) an exception was raised:
** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1
(elixir 1.17.3) lib/io.ex:696: IO.chardata_to_string(nil)
(elixir 1.17.3) lib/path.ex:681: Path.do_join/3 (elixir 1.17.3) lib/path.ex:673: Path.join/2 (elixir 1.17.3) lib/path.ex:641: Path.join/1
(pleroma 3.15.2) lib/pleroma/web/media_proxy.ex:82: Pleroma.Web.MediaProxy.whitelisted?/1
(pleroma 3.15.2) lib/pleroma/web/media_proxy.ex:55: Pleroma.Web.MediaProxy.url_proxiable?/1
(pleroma 3.15.2) lib/pleroma/web/media_proxy.ex:46: Pleroma.Web.MediaProxy.url/1
(pleroma 3.15.2) lib/pleroma/web/mastodon_api/views/account_view.ex:208: Pleroma.Web.MastodonAPI.AccountView.do_render/2

looks to me like you may have set a nil value in your media proxy whitelist config - it’s complaining about that specific config key

Thanks. I assume you mean the whitelist setting located at https://social.example.com/pleroma/admin/#/settings/media-proxy ?

That field is empty. I put in https://social.example.com , enabled and submitted and the same error threw.

FWIW, I am not seeing Nginx rebuild the 1:2 cache, the directory is empty.

Is there something like:

/usr/local/bin/mix pleroma.config delete pleroma media_proxy

That might be able to be run to remove the offending config from the database?

Edit:

So I ran:

$ /usr/local/bin/mix pleroma.config dump | grep media
config :pleroma, :media_proxy, [enabled: true]

I then ran:

/usr/local/bin/mix pleroma.config delete pleroma media_proxy

Which removed whitelist but the problem persists when enabling again. I’m happy to provide the full config in private DM if easier?

waaaaait, that config… have you set its base_url?

see: akkoma/lib/pleroma/web/media_proxy.ex at stable - AkkomaGang/akkoma - Akkoma Development

Upload.base_url being unset would cause this

I have that removed from the DB and is in prod.secrets.conf as:

config :pleroma, :media_proxy,
enabled: true,
redirect_on_failure: false,
base_url: “https://social.example.[com]”

I also changed the base URL to [https]://media.social.example.[com] with no success.

Error is thrown straight after:

17:00:52.737 [info] Found emoji packs:
17:00:52.786 [info] Running Pleroma.Web.Endpoint with cowboy 2.13.0 at 127.0.0.1:4000 (http)
17:00:52.786 [info] Access Pleroma.Web.Endpoint at [https]://social.example.[com]

Further in:

17:10:31.029 [error] !!!WARNING!!!
Your Akkoma Host and your Upload base_url’s host are the same! This can potentially be insecure!
It is HIGHLY recommended that you migrate your media uploads to a subdomain at your earliest convenience

config :pleroma, Pleroma.Upload, base_url: “[https]://social.example.com”, filters: [Pleroma.Upload.Filter.Exiftool.StripLocation]

the only possible causes are that you have an invalid whitelist , or an invalid base URL

I cannot debug your setup further

No worries. Thanks for your help. I’ll keep trying different ideas and will report back if I get this sorted either way. Cheers.

Note how directly after media proxy’s whitelisted function,Path.join shows up in the stacktrace and only later the attempted conversion of nil to a charlist.

This implies it’s not failing to convert the result of the base_url call, but already before the latter returns (i’m guessing it’s not showing up in the stacktrace itself because it’s inlined or something).
base_url only calls Path.join if using S3 uploads and most likely the bucket setting not base_url is nil

Thanks so much. That pointed me in the right direction and I have fixed the issue. For some reason, Truncated Namespace for S3 configuration in Upload was null. Setting it to ““ resolved the issue and is rapidly filling up the NGINX cache as intended.

Thank you both for your patience and helping solve this issue. Cheers.

SOLVED: Issue Now Closed.