trenpixster / addict

User management lib for Phoenix Framework
MIT License
645 stars 99 forks source link

All routes return (Poison.EncodeError) unable to encode value: {nil, "users"} #56

Closed mrluc closed 9 years ago

mrluc commented 9 years ago

So, actions like /register take appropriate database effect, but explode trying to return a json response with the aforementioned error.

Unfortunately the Poison error thrown gives a stacktrace that's very unhelpful! So I rather have to guess that this is happening in Addict.Controller's register code when it tries to call json conn, message, as this happens with default addict routes handling the /register POST:

[info] POST /register
[debug] Processing by Addict.Controller.register/2
  Parameters: %{"_csrf_token" => "QDFUHx4yDgxVF3tCHwVaHzBzQVMZEAAApe6hzuyNfdC8MlhEBKr4Jw==", "email" => "hambone@example.com", "format" => "html", "password" => "[FILTERED]", "username" => "mrluc"}
  Pipelines: [:browser]
[debug] BEGIN [] OK query=0.4ms
[debug] INSERT INTO "users" ("email", "hash", "inserted_at", "recovery_hash", "updated_at", "username") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" ["hambone@example.com", "$pbkdf2-sha512$60000$Aji.Gc/s3A7oiM/TWWH3WA$E7eill52.Jg7KMhYifgOW0ZXG/A8mebWrlsfaHyM14WdDhSa9yEDAN6C6UFpikGYsUMpH74WcpMNwE6jGUVOGw", {{2015, 8, 14}, {23, 17, 4, 0}}, nil, {{2015, 8, 14}, {23, 17, 4, 0}}, "mrluc"] OK query=0.9ms
[debug] COMMIT [] OK query=6.4ms
[info] Sent 500 in 968ms
[error] #PID<0.490.0> running Flashbang.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /register
** (exit) an exception was raised:
    ** (Poison.EncodeError) unable to encode value: {nil, "users"}
        (poison) lib/poison/encoder.ex:213: Poison.Encoder.Any.encode/2
        (poison) lib/poison/encoder.ex:156: anonymous fn/4 in Poison.Encoder.Map.encode/2
        (stdlib) lists.erl:1261: :lists.foldl/3
        (poison) lib/poison/encoder.ex:157: Poison.Encoder.Map.encode/2
        (poison) lib/poison/encoder.ex:156: anonymous fn/4 in Poison.Encoder.Map.encode/2
        (stdlib) lists.erl:1261: :lists.foldl/3
        (poison) lib/poison/encoder.ex:157: Poison.Encoder.Map.encode/2
        (poison) lib/poison/encoder.ex:156: anonymous fn/4 in Poison.Encoder.Map.encode/2
mrluc commented 9 years ago

After digging into the codebase, I see that the issue is that addict is feeding an Ecto-based struct to Poison and telling it to encode it to iodata, and it dies because of fields like __struct__ that it can't serialize.

Turns out, that's been fixed in git, just not the hex.pm package. Switching to git deps for addict solved it for me.

trenpixster commented 9 years ago

Sorry, will update the hex.pm package with the latest changes :+1:

trenpixster commented 9 years ago

Published 0.1.0

srajappa commented 8 years ago

I am sure it is an encoding error which gets reflected in the stack-trace here. I guess I should look for answers in the controller AppController. Is that the case ?

08:40:17.418 request_id=nMaM8lZOYm06c6PuI4C3 [info] Processing by Grandcentral.Api.AppController.index/2
  Parameters: %{"format" => "json"}
  Pipelines: [:api, :any_auth]
08:40:17.639 request_id=nMaM8lZOYm06c6PuI4C3 [info] Sent 500 in 240ms
08:40:17.656 [error] #PID<0.495.0> running Grandcentral.Endpoint terminated
Server: gc-dev.zappos.biz:4000 (http)
Request: GET /api/apps
** (exit) an exception was raised:
    ** (Poison.EncodeError) unable to encode value: {nil, "apps"}
        (poison) lib/poison/encoder.ex:339: Poison.Encoder.Any.encode/2
        (poison) lib/poison/encoder.ex:213: anonymous fn/4 in Poison.Encoder.Map.encode/3
        (poison) lib/poison/encoder.ex:214: Poison.Encoder.Map."-encode/3-lists^foldl/2-0-"/3
        (poison) lib/poison/encoder.ex:214: Poison.Encoder.Map.encode/3
        (poison) lib/poison/encoder.ex:213: anonymous fn/4 in Poison.Encoder.Map.encode/3
        (poison) lib/poison/encoder.ex:214: Poison.Encoder.Map."-encode/3-lists^foldl/2-0-"/3
        (poison) lib/poison/encoder.ex:214: Poison.Encoder.Map.encode/3
        (poison) lib/poison/encoder.ex:232: anonymous fn/3 in Poison.Encoder.List.encode/3