Elixir IEx.pry用于调试参数错误:erlang.binary\u to\u integer

Elixir IEx.pry用于调试参数错误:erlang.binary\u to\u integer,elixir,phoenix-framework,Elixir,Phoenix Framework,当我在玩这里找到的Phoenix starter示例时,我遇到了这个错误,我在调试时遇到了困难 Compiled web/connection.ex [info] OPTIONS /api/v1/current_user [info] Sent 204 in 74µs Compiled web/connection.ex [info] GET /api/v1/current_user [info] Sent 500 in 23ms [error] #PID<0.418.0> runn

当我在玩这里找到的Phoenix starter示例时,我遇到了这个错误,我在调试时遇到了困难

Compiled web/connection.ex
[info] OPTIONS /api/v1/current_user
[info] Sent 204 in 74µs
Compiled web/connection.ex
[info] GET /api/v1/current_user
[info] Sent 500 in 23ms
[error] #PID<0.418.0> running ReactPhoenix.Endpoint terminated
Server: localhost:4000 (http)
Request: GET /api/v1/current_user?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJVc2VyOmMyZDBmZGQ5LWJkNTUtNDJkNS1iMmJlLTAzYjRkNThkOTg0YyIsInBlbSI6e30sImp0aSI6IjAxZGIxNjQ2LTZmZGEtNGI3Yy04YTI1LTRhZWFhYjAzMjE0NiIsImlzcyI6IlJlYWN0UGhvZW5peCIsImlhdCI6MTQ1NDI1MjE4NCwiZXhwIjoxNDU0NTExMzg0LCJhdWQiOiJ0b2tlbiJ9.YiGd-r2g7w7DiAvicq2C0uqhrwM4ZnUXRlnLg53GLag
** (exit) an exception was raised:
    ** (ArgumentError) argument error
        :erlang.binary_to_integer("c2d0fdd9-bd55-42d5-b2be-03b4d58d984c")
        (react_phoenix) lib/react_phoenix/guardian_serializer.ex:10: ReactPhoenix.GuardianSerializer.from_token/1
        lib/guardian/plug/load_resource.ex:27: Guardian.Plug.LoadResource.call/2 
        (react_phoenix) web/router.ex:13: ReactPhoenix.Router.api/2
        (react_phoenix) web/router.ex:1: ReactPhoenix.Router.match/4
        (react_phoenix) web/router.ex:1: ReactPhoenix.Router.do_call/2
        (react_phoenix) lib/react_phoenix/endpoint.ex:1: ReactPhoenix.Endpoint.phoenix_pipeline/1
        (react_phoenix) lib/plug/debugger.ex:93: ReactPhoenix.Endpoint."call (overridable 3)"/2
        (react_phoenix) lib/phoenix/endpoint/render_errors.ex:34: ReactPhoenix.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
Compiled web/connection.ex
[信息]选项/api/v1/当前用户
[信息]以74µs发送204
已编译的web/connection.ex
[info]GET/api/v1/current_用户
[信息]在23毫秒内发送500
[错误]#PID正在运行。终结点已终止
服务器:本地主机:4000(http)
请求:获取/api/v1/current_user?jwt=EYJ0Exiaioijkv1qiljHbgChiuzi1Nij9.EYJzdWioijvc2vyommyzdbmzgq5Lwjknutndjknskotg0yyisinblbSi6e30Simp0Asi6ijaxjxNjq2ltzmetzngi3y04yytrHwjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
**(退出)引发了一个异常:
**(ArgumentError)参数错误
:erlang.二进制到整数(“c2d0fdd9-bd55-42d5-b2be-03b4d58d984c”)
(react_phoenix)lib/react_phoenix/guardian_序列化程序。例如:10:ReactPhoenix.guarderserializer.from_token/1
lib/guardian/plug/load_resource.ex:27:guardian.plug.LoadResource.call/2
(react_phoenix)web/router.ex:13:ReactPhoenix.router.api/2
(react_phoenix)web/router.ex:1:ReactPhoenix.router.match/4
(react_phoenix)web/router.ex:1:react phoenix.router.do_call/2
(react_phoenix)lib/react_phoenix/endpoint.ex:1:ReactPhoenix.endpoint.phoenix_管道/1
(react_phoenix)lib/plug/debugger.ex:93:ReactPhoenix.Endpoint.“调用(可重写3)”/2
(react_phoenix)lib/phoenix/endpoint/render_errors.ex:34:ReactPhoenix.endpoint.call/2
(plug)lib/plug/adapters/cowboy/handler.ex:15:plug.adapters.cowboy.handler.upgrade/4
(cowboy)src/cowboy_protocol.erl:442::cowboy_protocol.execute/4
错误消息指向的模块如下所示。我尝试了IEx.pry(如注释掉的代码所示),但它不会暂停代码以供检查,即使服务器是通过IEx-S mix phoenix.server启动的

defmodule ReactPhoenix.GuardianSerializer do
require IEx
  @behaviour Guardian.Serializer

  alias ReactPhoenix.Repo
  alias ReactPhoenix.User

  def for_token(user = %User{}), do: { :ok, "User:#{user.id}" }
  def for_token(_), do: { :error, "Unknown resource type" }

  def from_token("User:" <> id), do: { :ok, Repo.get(User, String.to_integer(id)) }   # This is line 10

  #def from_token("User:" <> id), do
  #  IEx.pry
  #  IO.inspect id
  #  { :ok, Repo.get(User, String.to_integer(id)) }
  #  end

  def from_token(_), do: { :error, "Unknown resource type" }
end
defmodule.guarderserializer do
需要IEx
@行为卫报.序列化程序
别名:凤凰城
别名:phoenix.User
_令牌(user=%user{})的def,do:{:确定,“user:{user.id}”
_令牌(u)的定义,do:{:错误,“未知资源类型”}
def from_token(“User:”id),do:{:ok,Repo.get(User,String.to_integer(id))}这是第10行
#来自_令牌的def(“用户:”id),do
#撬动
#检查id
#{:好的,Repo.get(User,String.to_integer(id))}
#结束
来自_令牌(u)的def,do:{:错误,“未知资源类型”}
结束
编辑:我刚意识到我很傻,就茫然地读了这篇文章。实际上,它看起来像是将一个字符串(UUID)强制为整数,这永远不会起作用,因为它不是字符串的整数表示形式。如果您还没有弄明白,请发表评论,或者打电话给我,如果需要,我将帮助您进一步调试。

这一行表示此时您正在使用字符列表,而您应该使用字符串,反之亦然。在Elixir
中,字符串被视为二进制文件,
被视为字符列表

String.to_char_list

应该能够帮助您,并在上面提到的地方转换它。如果您在该行之前放置IEx.pry,您应该能够插入并测试它

String.to_char_list
String.to_string