如何调试凤凰框架的日志错误?



我正在安装这个phoenix web应用程序:https://github.com/poanetwork/blockscout

安装完所有依赖项后,我运行以下命令(按照文档):

$ mix phx.server

and got error:

$ iex -S mix phx.server
Erlang/OTP 25 [erts-13.1.2] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit:ns]
2022-12-13T04:25:43.083 [notice] Application ethereum_jsonrpc exited: EthereumJSONRPC.Application.start(:normal, []) returned an error: shutdown: failed to start child: :worker
** (EXIT) an exception was raised:
** (MatchError) no match of right hand side value: {:error, :badarg}
(poolboy 1.5.2) /opt/app/blockscout/deps/poolboy/src/poolboy.erl:283: :poolboy.new_worker/1
(poolboy 1.5.2) /opt/app/blockscout/deps/poolboy/src/poolboy.erl:304: :poolboy.prepopulate/3
(poolboy 1.5.2) /opt/app/blockscout/deps/poolboy/src/poolboy.erl:153: :poolboy.init/3
(stdlib 4.1.1) gen_server.erl:851: :gen_server.init_it/2
(stdlib 4.1.1) gen_server.erl:814: :gen_server.init_it/6
(stdlib 4.1.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
2022-12-13T04:25:43.106 [notice] Application poolboy exited: :stopped
2022-12-13T04:25:43.106 [notice] Application decorator exited: :stopped
2022-12-13T04:25:43.106 [notice] Application decimal exited: :stopped
2022-12-13T04:25:43.106 [notice] Application websocket_client exited: :stopped
2022-12-13T04:25:43.106 [notice] Application ex_abi exited: :stopped
2022-12-13T04:25:43.106 [notice] Application ex_keccak exited: :stopped
2022-12-13T04:25:43.106 [notice] Application rustler exited: :stopped
2022-12-13T04:25:43.107 [notice] Application timex exited: :stopped
2022-12-13T04:25:43.107 [notice] Application gettext exited: :stopped
2022-12-13T04:25:43.108 [notice] Application combine exited: :stopped
2022-12-13T04:25:43.110 [notice] Application tzdata exited: :stopped
2022-12-13T04:25:43.110 [notice] Application spandex_datadog exited: :stopped
2022-12-13T04:25:43.111 [notice] Application msgpax exited: :stopped
2022-12-13T04:25:43.111 [notice] Application spandex exited: :stopped
2022-12-13T04:25:43.111 [notice] Application plug exited: :stopped
2022-12-13T04:25:43.111 [notice] Application telemetry exited: :stopped
2022-12-13T04:25:43.112 [notice] Application plug_crypto exited: :stopped
2022-12-13T04:25:43.112 [notice] Application mime exited: :stopped
2022-12-13T04:25:43.112 [notice] Application eex exited: :stopped
2022-12-13T04:25:43.112 [notice] Application optimal exited: :stopped
2022-12-13T04:25:43.112 [notice] Application logger_file_backend exited: :stopped
2022-12-13T04:25:43.112 [notice] Application jason exited: :stopped
2022-12-13T04:25:43.112 [notice] Application httpoison exited: :stopped
2022-12-13T04:25:43.113 [notice] Application hackney exited: :stopped
2022-12-13T04:25:43.113 [notice] Application metrics exited: :stopped
2022-12-13T04:25:43.113 [notice] Application ssl_verify_fun exited: :stopped
2022-12-13T04:25:43.113 [notice] Application parse_trans exited: :stopped
2022-12-13T04:25:43.113 [notice] Application syntax_tools exited: :stopped
2022-12-13T04:25:43.113 [notice] Application mimerl exited: :stopped
2022-12-13T04:25:43.113 [notice] Application idna exited: :stopped
2022-12-13T04:25:43.113 [notice] Application unicode_util_compat exited: :stopped
2022-12-13T04:25:43.113 [notice] Application cowboy exited: :stopped
2022-12-13T04:25:43.114 [notice] Application ranch exited: :stopped
2022-12-13T04:25:43.114 [notice] Application cowlib exited: :stopped
2022-12-13T04:25:43.114 [notice] Application certifi exited: :stopped
** (Mix) Could not start application ethereum_jsonrpc: EthereumJSONRPC.Application.start(:normal, []) returned an error: shutdown: failed to start child: :worker
** (EXIT) an exception was raised:
** (MatchError) no match of right hand side value: {:error, :badarg}
(poolboy 1.5.2) /opt/app/blockscout/deps/poolboy/src/poolboy.erl:283: :poolboy.new_worker/1
(poolboy 1.5.2) /opt/app/blockscout/deps/poolboy/src/poolboy.erl:304: :poolboy.prepopulate/3
(poolboy 1.5.2) /opt/app/blockscout/deps/poolboy/src/poolboy.erl:153: :poolboy.init/3
(stdlib 4.1.1) gen_server.erl:851: :gen_server.init_it/2
(stdlib 4.1.1) gen_server.erl:814: :gen_server.init_it/6
(stdlib 4.1.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

我发现源代码没有堆栈跟踪,所有可以看到的堆栈跟踪都是依赖项。

那么我的问题是:如何知道which line of the source code的这个错误发生在哪里?

谢谢。

在应用程序试图启动之前就发生了错误。

ErlangVM尝试启动您的所有应用程序取决于预先,并且错误

Application ethereum_jsonrpc exited:
EthereumJSONRPC.Application.start(:normal, []) returned an error:
shutdown: failed to start child: :worker
** (EXIT) an exception was raised:
** (MatchError) no match of right hand side value: {:error, :badarg}

基本上表示ethereum_jsonrpc应用程序启动失败,阻止ErlangVM尝试启动主应用程序。为了缩小问题范围,可以尝试显式地启动失败的ethereum_jsonrpc,例如从iex会话与Application.ensure_all_started(:ethereum_jsonrpc)或更显式的EthereumJSONRPC.Application.start(:normal, [])

好了,我解决了。

最后我不知道哪一行代码出错了。

<标题>

解决方案1。将多个调试日志打印到源代码中,并猜测出错的步骤。

+    IO.puts "== config: #{ inspect config}"
+    IO.puts "== rolling_window_opts: #{ inspect rolling_window_opts}"

,并且,在phoenix框架中,您可以从其CalssName猜测源代码文件,例如

EthereumJSONRPC.Application映射到apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex

2。修改日志级别

3。编辑config/config.exs文件以启用DB日志:

database: database_api,
hostname: hostname_api,
// add this line of code
show_sensitive_data_on_connection_error: true

最新更新