Skip to content

update_credentials failure results in unexpected behaviour

When trying to update account credentials via the /api/v1/accounts/update_credentials path and errors like :file_too_large are encountered, the account details are cleared and it fails silently.

The request returns a very ambiguous HTTP 500 error but it doesn't display that at all.

{"errors":{"detail":"Internal server error"}}

scr-15_12_50

Related log snippet
16:07:21.917 request_id=FkxRgcOy2g3YY7UAZ7sx [error] Elixir.Pleroma.Upload store (using Pleroma.Uploaders.Local) failed: :file_too_large
16:07:21.959 request_id=FkxRgcOy2g3YY7UAZ7sx [error] Internal server error: %Protocol.UndefinedError{description: "Jason.Encoder protocol must always be explicitly implemented.\n\nIf you own the struct>
16:07:21.959 request_id=FkxRgcOy2g3YY7UAZ7sx [info] Converted error Protocol.UndefinedError to 500 response
16:07:21.966 [error] #PID<0.1508.56> running Pleroma.Web.Endpoint (connection #PID<0.31899.55>, stream id 92) terminated
Server: social.redxen.eu:80 (http)
Request: PATCH /api/v1/accounts/update_credentials
** (exit) an exception was raised:
    ** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for %Plug.Upload{content_type: "image/gif", filename: "out.gif", path: "/tmp/plug-1606/multipart-1606748785-144015104872266-1"} o>
If you own the struct, you can derive the implementation specifying which fields should be encoded to JSON:
    @derive {Jason.Encoder, only: [....]}
    defstruct ...
It is also possible to encode all fields, although this should be used carefully to avoid accidentally leaking private information when new fields are added:
    @derive Jason.Encoder
    defstruct ...
Finally, if you don't own the struct you want to encode to JSON, you may use Protocol.derive/3 placed outside of any module:
    Protocol.derive(Jason.Encoder, NameOfTheStruct, only: [...])
    Protocol.derive(Jason.Encoder, NameOfTheStruct)
. This protocol is implemented for the following type(s): Pleroma.Web.ApiSpec.Schemas.Attachment, Pleroma.Healthcheck, Pleroma.Web.ApiSpec.Schemas.ApiError, Function, Pleroma.Web.ApiSpec.Schemas.List, >
        (jason 1.2.1) lib/jason.ex:199: Jason.encode_to_iodata!/2
        (pleroma 2.1.50-259-g49584a99-develop) deps/postgrex/lib/postgrex/type_module.ex:897: Pleroma.PostgresTypes.encode_params/3
        (postgrex 0.15.5) lib/postgrex/query.ex:75: DBConnection.Query.Postgrex.Query.encode/3
        (db_connection 2.2.2) lib/db_connection.ex:1148: DBConnection.encode/5
        (db_connection 2.2.2) lib/db_connection.ex:1246: DBConnection.run_prepare_execute/5
        (db_connection 2.2.2) lib/db_connection.ex:539: DBConnection.parsed_prepare_execute/5
        (db_connection 2.2.2) lib/db_connection.ex:532: DBConnection.prepare_execute/4
        (postgrex 0.15.5) lib/postgrex.ex:214: Postgrex.query/4

Pleroma FE version (commit): b225c357