Clean up code and handle crash ping variations better

This commit is contained in:
Will Kahn-Greene 2022-12-06 08:53:25 -05:00 коммит произвёл Will Kahn-Greene
Родитель e3a90d7bc4
Коммит f97d6a813f
4 изменённых файлов: 19 добавлений и 30 удалений

Просмотреть файл

@ -8,27 +8,7 @@ from siggen.generator import SignatureGenerator
from fx_crash_sig import SYMBOLICATION_API
from fx_crash_sig.symbolicate import Symbolicator
def deep_get(data, path, default=None):
"""Retrieves a node in the structure by dotted path
:arg data: structure of Python dicts
:arg path: dotted path string to the item in question
:arg default: default value to return if the item doesn't exist
:returns: the item in question or default
"""
item = data
path = path.split(".")
for part in path:
if isinstance(item, dict) and part in item:
item = item[part]
else:
return default
return item
from fx_crash_sig.utils import deep_get
class CrashProcessor:
@ -95,10 +75,10 @@ class CrashProcessor:
# do with this crash report
payload = json.loads(payload)
metadata = payload.get("metadata", {})
stack_traces = payload["stack_traces"]
metadata = payload.get("metadata") or {}
stack_traces = payload.get("stack_traces") or {}
if stack_traces is None or len(stack_traces) == 0:
if len(stack_traces) == 0:
symbolicated = {}
elif metadata.get("ipc_channel_error"):
# ipc_channel_error will always overwrite the crash signature so

Просмотреть файл

@ -9,7 +9,7 @@ from fx_crash_sig.crash_processor import CrashProcessor
def wrap_in_payload(crash_data):
return {"metadata": {}, "stackTraces": crash_data}
return {"metadata": {}, "stack_traces": crash_data}
if __name__ == "__main__":

Просмотреть файл

@ -7,6 +7,7 @@ from itertools import islice
import requests
from fx_crash_sig import SYMBOLICATION_API, __version__
from fx_crash_sig.utils import deep_get
class Symbolicator:
@ -78,7 +79,10 @@ class Symbolicator:
print(f"src_frame: {src_frame}")
continue
module_index = src_frame["module_index"]
module_index = src_frame.get("module_index")
if module_index is None:
continue
if not (module_index >= 0 and module_index < len(modules)):
raise ValueError(
f"module {module_index} out of frange for thread {thread_idx} "
@ -126,7 +130,10 @@ class Symbolicator:
return self.empty_request
sym_request = {
"stacks": [[f["lookup"] for f in t] for t in threads_to_symbolicate],
"stacks": [
[frame["lookup"] for frame in thread]
for thread in threads_to_symbolicate
],
"memoryMap": [
[debug_file, debug_id]
for (debug_file, debug_id) in modules_to_symbolicate
@ -173,10 +180,12 @@ class Symbolicator:
:param list traces: list of raw crash traces
:return: list of symbolicated traces
"""
symbolication_requests = {"jobs": [self.__try_get_sym_req(t) for t in traces]}
symbolication_requests = {
"jobs": [self.__try_get_sym_req(trace) for trace in traces]
}
crashing_threads = [
t.get("crash_info", {}).get("crashing_thread", 0) if t else 0
for t in traces
deep_get(trace, "crash_info.crashing_thread", default=0) if trace else 0
for trace in traces
]
try:

Просмотреть файл