Refactor `try rescue` statements to keep stacktrace (#6786)

* Refactor try rescue statements to keep stacktrace

* Update CHANGELOG.md
pull/6586/merge
Maxim Filonov 2 years ago committed by GitHub
parent cfc1fa46fe
commit 85963ef02f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .credo.exs
  2. 1
      CHANGELOG.md
  3. 2
      apps/block_scout_web/lib/block_scout_web/plug/redis_cookie.ex
  4. 6
      apps/block_scout_web/lib/block_scout_web/views/abi_encoded_value_view.ex
  5. 2
      apps/explorer/lib/explorer/account/notify.ex
  6. 3
      apps/explorer/lib/explorer/chain/cache/address_sum.ex
  7. 3
      apps/explorer/lib/explorer/chain/cache/address_sum_minus_burnt.ex
  8. 3
      apps/explorer/lib/explorer/chain/cache/block.ex
  9. 3
      apps/explorer/lib/explorer/chain/cache/gas_price_oracle.ex
  10. 3
      apps/explorer/lib/explorer/chain/cache/gas_usage.ex
  11. 3
      apps/explorer/lib/explorer/chain/cache/transaction.ex
  12. 2
      apps/explorer/lib/explorer/chain/contract_method.ex
  13. 10
      apps/explorer/lib/explorer/chain/log.ex
  14. 22
      apps/explorer/lib/explorer/chain/transaction.ex
  15. 4
      apps/explorer/lib/explorer/smart_contract/solidity/verifier.ex
  16. 2
      apps/explorer/lib/explorer/smart_contract/vyper/verifier.ex
  17. 20
      apps/explorer/lib/explorer/token/instance_metadata_retriever.ex
  18. 28
      apps/indexer/lib/indexer/fetcher/internal_transaction.ex
  19. 2
      apps/indexer/lib/indexer/fetcher/replaced_transaction.ex
  20. 7
      apps/indexer/lib/indexer/transform/token_transfers.ex

@ -131,7 +131,7 @@
{Credo.Check.Warning.UnusedRegexOperation}, {Credo.Check.Warning.UnusedRegexOperation},
{Credo.Check.Warning.UnusedStringOperation}, {Credo.Check.Warning.UnusedStringOperation},
{Credo.Check.Warning.UnusedTupleOperation}, {Credo.Check.Warning.UnusedTupleOperation},
{Credo.Check.Warning.RaiseInsideRescue, false}, {Credo.Check.Warning.RaiseInsideRescue},
# Controversial and experimental checks (opt-in, just remove `, false`) # Controversial and experimental checks (opt-in, just remove `, false`)
# #

@ -23,6 +23,7 @@
### Chore ### Chore
- [#6786](https://github.com/blockscout/blockscout/pull/6786) - Refactor `try rescue` statements to keep stacktrace
- [#6695](https://github.com/blockscout/blockscout/pull/6695) - Process errors and warnings with enables check-js feature in VS code - [#6695](https://github.com/blockscout/blockscout/pull/6695) - Process errors and warnings with enables check-js feature in VS code
<details> <details>

@ -72,7 +72,7 @@ defmodule BlockScoutWeb.Plug.RedisCookie do
Logger.log( Logger.log(
log, log,
"Plug.Session could not decode incoming session cookie. Reason: " <> "Plug.Session could not decode incoming session cookie. Reason: " <>
Exception.message(e) Exception.format(:error, e, __STACKTRACE__)
) )
%{} %{}

@ -21,7 +21,7 @@ defmodule BlockScoutWeb.ABIEncodedValueView do
rescue rescue
exception -> exception ->
Logger.warn(fn -> Logger.warn(fn ->
["Error determining value html for #{inspect(type)}: ", Exception.format(:error, exception)] ["Error determining value html for #{inspect(type)}: ", Exception.format(:error, exception, __STACKTRACE__)]
end) end)
:error :error
@ -34,7 +34,7 @@ defmodule BlockScoutWeb.ABIEncodedValueView do
rescue rescue
exception -> exception ->
Logger.warn(fn -> Logger.warn(fn ->
["Error determining value json for #{inspect(type)}: ", Exception.format(:error, exception)] ["Error determining value json for #{inspect(type)}: ", Exception.format(:error, exception, __STACKTRACE__)]
end) end)
nil nil
@ -47,7 +47,7 @@ defmodule BlockScoutWeb.ABIEncodedValueView do
rescue rescue
exception -> exception ->
Logger.warn(fn -> Logger.warn(fn ->
["Error determining copy text for #{inspect(type)}: ", Exception.format(:error, exception)] ["Error determining copy text for #{inspect(type)}: ", Exception.format(:error, exception, __STACKTRACE__)]
end) end)
:error :error

@ -20,7 +20,7 @@ defmodule Explorer.Account.Notify do
rescue rescue
err -> err ->
Logger.info("--- Notifier error", fetcher: :account) Logger.info("--- Notifier error", fetcher: :account)
Logger.info(err, fetcher: :account) :error |> Exception.format(err, __STACKTRACE__) |> Logger.info(fetcher: :account)
end end
defp check_envs do defp check_envs do

@ -35,7 +35,8 @@ defmodule Explorer.Chain.Cache.AddressSum do
rescue rescue
e -> e ->
Logger.debug([ Logger.debug([
"Coudn't update address sum test #{inspect(e)}" "Coudn't update address sum: ",
Exception.format(:error, e, __STACKTRACE__)
]) ])
end end

@ -42,7 +42,8 @@ defmodule Explorer.Chain.Cache.AddressSumMinusBurnt do
rescue rescue
e -> e ->
Logger.debug([ Logger.debug([
"Coudn't update address sum test #{inspect(e)}" "Coudn't update address sum: ",
Exception.format(:error, e, __STACKTRACE__)
]) ])
end end

@ -61,7 +61,8 @@ defmodule Explorer.Chain.Cache.Block do
rescue rescue
e -> e ->
Logger.debug([ Logger.debug([
"Coudn't update block count test #{inspect(e)}" "Coudn't update block count: ",
Exception.format(:error, e, __STACKTRACE__)
]) ])
end end

@ -105,7 +105,8 @@ defmodule Explorer.Chain.Cache.GasPriceOracle do
rescue rescue
e -> e ->
Logger.debug([ Logger.debug([
"Coudn't update gas used gas_prices #{inspect(e)}" "Coudn't update gas used gas_prices",
Exception.format(:error, e, __STACKTRACE__)
]) ])
end end

@ -57,7 +57,8 @@ defmodule Explorer.Chain.Cache.GasUsage do
rescue rescue
e -> e ->
Logger.debug([ Logger.debug([
"Coudn't update gas used sum test #{inspect(e)}" "Coudn't update gas used sum: ",
Exception.format(:error, e, __STACKTRACE__)
]) ])
end end

@ -58,7 +58,8 @@ defmodule Explorer.Chain.Cache.Transaction do
rescue rescue
e -> e ->
Logger.debug([ Logger.debug([
"Coudn't update transaction count test #{inspect(e)}" "Coudn't update transaction count: ",
Exception.format(:error, e, __STACKTRACE__)
]) ])
end end

@ -87,7 +87,7 @@ defmodule Explorer.Chain.ContractMethod do
end end
rescue rescue
e -> e ->
message = Exception.format(:error, e) message = Exception.format(:error, e, __STACKTRACE__)
{:error, message} {:error, message}
end end

@ -218,8 +218,14 @@ defmodule Explorer.Chain.Log do
{:ok, selector, mapping} {:ok, selector, mapping}
end end
rescue rescue
_ -> e ->
Logger.warn(fn -> ["Could not decode input data for log from transaction: ", Hash.to_iodata(transaction.hash)] end) Logger.warn(fn ->
[
"Could not decode input data for log from transaction: ",
Hash.to_iodata(transaction.hash),
Exception.format(:error, e, __STACKTRACE__)
]
end)
{:error, :could_not_decode} {:error, :could_not_decode}
end end

@ -674,8 +674,15 @@ defmodule Explorer.Chain.Transaction do
{:ok, result} {:ok, result}
rescue rescue
_ -> e ->
Logger.warn(fn -> ["Could not decode input data for transaction: ", Hash.to_iodata(hash)] end) Logger.warn(fn ->
[
"Could not decode input data for transaction: ",
Hash.to_iodata(hash),
Exception.format(:error, e, __STACKTRACE__)
]
end)
{:error, :could_not_decode} {:error, :could_not_decode}
end end
@ -686,8 +693,15 @@ defmodule Explorer.Chain.Transaction do
{:ok, mapping} {:ok, mapping}
rescue rescue
_ -> e ->
Logger.warn(fn -> ["Could not decode input data for transaction: ", Hash.to_iodata(hash)] end) Logger.warn(fn ->
[
"Could not decode input data for transaction: ",
Hash.to_iodata(hash),
Exception.format(:error, e, __STACKTRACE__)
]
end)
{:error, :could_not_decode} {:error, :could_not_decode}
end end

@ -30,7 +30,7 @@ defmodule Explorer.SmartContract.Solidity.Verifier do
Logger.error(fn -> Logger.error(fn ->
[ [
"Error while verifying smart-contract address: #{address_hash}, params: #{inspect(params, limit: :infinity, printable_limit: :infinity)}: ", "Error while verifying smart-contract address: #{address_hash}, params: #{inspect(params, limit: :infinity, printable_limit: :infinity)}: ",
Exception.format(:error, exception) Exception.format(:error, exception, __STACKTRACE__)
] ]
end) end)
end end
@ -117,7 +117,7 @@ defmodule Explorer.SmartContract.Solidity.Verifier do
Logger.error(fn -> Logger.error(fn ->
[ [
"Error while verifying smart-contract address: #{address_hash}, params: #{inspect(params, limit: :infinity, printable_limit: :infinity)}, json_input: #{inspect(json_input, limit: :infinity, printable_limit: :infinity)}: ", "Error while verifying smart-contract address: #{address_hash}, params: #{inspect(params, limit: :infinity, printable_limit: :infinity)}, json_input: #{inspect(json_input, limit: :infinity, printable_limit: :infinity)}: ",
Exception.format(:error, exception) Exception.format(:error, exception, __STACKTRACE__)
] ]
end) end)
end end

@ -26,7 +26,7 @@ defmodule Explorer.SmartContract.Vyper.Verifier do
Logger.error(fn -> Logger.error(fn ->
[ [
"Error while verifying smart-contract address: #{address_hash}, params: #{inspect(params, limit: :infinity, printable_limit: :infinity)}: ", "Error while verifying smart-contract address: #{address_hash}, params: #{inspect(params, limit: :infinity, printable_limit: :infinity)}: ",
Exception.format(:error, exception) Exception.format(:error, exception, __STACKTRACE__)
] ]
end) end)
end end

@ -148,7 +148,7 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
fetch_json(%{@token_uri => {:ok, [decoded_json]}}, hex_token_id) fetch_json(%{@token_uri => {:ok, [decoded_json]}}, hex_token_id)
rescue rescue
e -> e ->
Logger.debug(["Unknown metadata format #{inspect(json)}. error #{inspect(e)}"], Logger.debug(["Unknown metadata format #{inspect(json)}.", Exception.format(:error, e, __STACKTRACE__)],
fetcher: :token_instances fetcher: :token_instances
) )
@ -161,7 +161,7 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
fetch_json(%{@uri => {:ok, [decoded_json]}}, hex_token_id) fetch_json(%{@uri => {:ok, [decoded_json]}}, hex_token_id)
rescue rescue
e -> e ->
Logger.debug(["Unknown metadata format #{inspect(json)}. error #{inspect(e)}"], Logger.debug(["Unknown metadata format #{inspect(json)}.", Exception.format(:error, e, __STACKTRACE__)],
fetcher: :token_instances fetcher: :token_instances
) )
@ -178,7 +178,11 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
end end
rescue rescue
e -> e ->
Logger.debug(["Unknown metadata format base64 #{inspect(base64_encoded_json)}. error #{inspect(e)}"], Logger.debug(
[
"Unknown metadata format base64 #{inspect(base64_encoded_json)}.",
Exception.format(:error, e, __STACKTRACE__)
],
fetcher: :token_instances fetcher: :token_instances
) )
@ -195,7 +199,8 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
end end
rescue rescue
e -> e ->
Logger.debug(["Unknown metadata format base64 #{inspect(base64_encoded_json)}. error #{inspect(e)}"], Logger.debug(
["Unknown metadata format base64 #{inspect(base64_encoded_json)}", Exception.format(:error, e, __STACKTRACE__)],
fetcher: :token_instances fetcher: :token_instances
) )
@ -228,7 +233,7 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
check_type(json, hex_token_id) check_type(json, hex_token_id)
rescue rescue
e -> e ->
Logger.debug(["Unknown metadata format #{inspect(json)}. error #{inspect(e)}"], Logger.debug(["Unknown metadata format #{inspect(json)}.", Exception.format(:error, e, __STACKTRACE__)],
fetcher: :token_instances fetcher: :token_instances
) )
@ -241,7 +246,7 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
check_type(json, hex_token_id) check_type(json, hex_token_id)
rescue rescue
e -> e ->
Logger.debug(["Unknown metadata format #{inspect(json)}. error #{inspect(e)}"], Logger.debug(["Unknown metadata format #{inspect(json)}.", Exception.format(:error, e, __STACKTRACE__)],
fetcher: :token_instances fetcher: :token_instances
) )
@ -282,7 +287,8 @@ defmodule Explorer.Token.InstanceMetadataRetriever do
end end
rescue rescue
e -> e ->
Logger.debug(["Could not send request to token uri #{inspect(uri)}. error #{inspect(e)}"], Logger.debug(
["Could not send request to token uri #{inspect(uri)}.", Exception.format(:error, e, __STACKTRACE__)],
fetcher: :token_instances fetcher: :token_instances
) )

@ -101,13 +101,7 @@ defmodule Indexer.Fetcher.InternalTransaction do
json_rpc_named_arguments json_rpc_named_arguments
|> Keyword.fetch!(:variant) |> Keyword.fetch!(:variant)
|> case do |> case do
EthereumJSONRPC.Nethermind -> variant when variant in [EthereumJSONRPC.Nethermind, EthereumJSONRPC.Erigon, EthereumJSONRPC.Besu] ->
EthereumJSONRPC.fetch_block_internal_transactions(filtered_unique_numbers, json_rpc_named_arguments)
EthereumJSONRPC.Erigon ->
EthereumJSONRPC.fetch_block_internal_transactions(filtered_unique_numbers, json_rpc_named_arguments)
EthereumJSONRPC.Besu ->
EthereumJSONRPC.fetch_block_internal_transactions(filtered_unique_numbers, json_rpc_named_arguments) EthereumJSONRPC.fetch_block_internal_transactions(filtered_unique_numbers, json_rpc_named_arguments)
_ -> _ ->
@ -115,7 +109,7 @@ defmodule Indexer.Fetcher.InternalTransaction do
fetch_block_internal_transactions_by_transactions(filtered_unique_numbers, json_rpc_named_arguments) fetch_block_internal_transactions_by_transactions(filtered_unique_numbers, json_rpc_named_arguments)
rescue rescue
error -> error ->
{:error, error} {:error, error, __STACKTRACE__}
end end
end end
|> case do |> case do
@ -123,7 +117,21 @@ defmodule Indexer.Fetcher.InternalTransaction do
safe_import_internal_transaction(internal_transactions_params, filtered_unique_numbers) safe_import_internal_transaction(internal_transactions_params, filtered_unique_numbers)
{:error, reason} -> {:error, reason} ->
Logger.error(fn -> ["failed to fetch internal transactions for blocks: ", inspect(reason)] end, Logger.error(
fn ->
["failed to fetch internal transactions for blocks: ", Exception.format(:error, reason)]
end,
error_count: filtered_unique_numbers_count
)
# re-queue the de-duped entries
{:retry, filtered_unique_numbers}
{:error, reason, stacktrace} ->
Logger.error(
fn ->
["failed to fetch internal transactions for blocks: ", Exception.format(:error, reason, stacktrace)]
end,
error_count: filtered_unique_numbers_count error_count: filtered_unique_numbers_count
) )
@ -171,7 +179,7 @@ defmodule Indexer.Fetcher.InternalTransaction do
EthereumJSONRPC.fetch_internal_transactions(transactions, json_rpc_named_arguments) EthereumJSONRPC.fetch_internal_transactions(transactions, json_rpc_named_arguments)
catch catch
:exit, error -> :exit, error ->
{:error, error} {:error, error, __STACKTRACE__}
end end
end end
|> case do |> case do

@ -123,7 +123,7 @@ defmodule Indexer.Fetcher.ReplacedTransaction do
Logger.error(fn -> Logger.error(fn ->
[ [
"failed to update replaced transactions for transactions: ", "failed to update replaced transactions for transactions: ",
inspect(reason) Exception.format(:error, reason, __STACKTRACE__)
] ]
end) end)

@ -67,8 +67,11 @@ defmodule Indexer.Transform.TokenTransfers do
token_transfers: [token_transfer | token_transfers] token_transfers: [token_transfer | token_transfers]
} }
rescue rescue
_ in [FunctionClauseError, MatchError] -> e in [FunctionClauseError, MatchError] ->
Logger.error(fn -> "Unknown token transfer format: #{inspect(log)}" end) Logger.error(fn ->
["Unknown token transfer format: #{inspect(log)}", Exception.format(:error, e, __STACKTRACE__)]
end)
acc acc
end end

Loading…
Cancel
Save