Last active
February 6, 2025 11:50
-
-
Save dominicletz/c85092db2373721605d7eef2dd86ca0c to your computer and use it in GitHub Desktop.
Parse BEAM errors from DeviceCloud logs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env elixir | |
Mix.install([:jason]) | |
filename = | |
case System.argv() do | |
[filename] -> | |
filename | |
_ -> | |
IO.puts("Missing filename") | |
System.halt(1) | |
end | |
with {:ok, content} <- File.read(filename), | |
{:ok, %{"logcatMessages" => messages}} <- Jason.decode(content) do | |
messages = | |
Enum.filter(messages, &(get_in(&1, ["header", "tag"]) == "BEAM")) | |
|> Enum.map(&get_in(&1, ["message"])) | |
|> Enum.join("") | |
# Filter bash color codes | |
|> String.replace(~r/\e\[([0-9;]*[mGKH])/, "") | |
# Ensure line break on error/warning/debug/info | |
|> String.replace(~r/[^\n]\[(error|warning|debug|info)\]/, "\n[\\1]") | |
# Remove s_glBindAttribLocation | |
|> String.replace(~r/s_glBindAttribLocation.*?\[/, "[") | |
|> String.replace(~r/s_glBindAttribLocation.*?\n/, "") | |
# Remove '[INFO:CONSOLE(6114)] "Uncaught TypeError: Cannot read properties of null (reading 'getData')", source: http://localhost:35548/assets/app-6505c1b539645f5436b117e3fce8d609.js?vsn=d (6114)' | |
|> String.replace(~r/\[INFO:CONSOLE\(([0-9]+)\).*?source: .*? \([0-9]+\)/, "") | |
|> String.replace("\\n", "\n") | |
|> String.split("\n", trim: true) | |
|> Enum.map(&String.trim/1) | |
|> Enum.with_index() | |
IO.puts("Errors:") | |
for {message, index} <- messages do | |
if String.starts_with?(message, "[error]") do | |
IO.puts(String.pad_leading("#{index + 1}: ", 5) <> String.trim(message)) | |
end | |
end | |
IO.puts("") | |
IO.puts("Full Log:") | |
for {message, index} <- messages do | |
if String.starts_with?(message, "[") or String.starts_with?(message, "bridge_") do | |
IO.puts(String.pad_leading("#{index + 1}: ", 6) <> String.trim(message)) | |
else | |
IO.puts(" " <> String.trim(message)) | |
end | |
end | |
else | |
{:ok, _} -> | |
IO.puts("Wrong json format, no logcatMessages key") | |
System.halt(1) | |
{:error, reason} -> | |
IO.puts("Error: #{reason}") | |
System.halt(1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment