From eea5f032e205e9b1e5acd6cd8399b86175b93ae9 Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Wed, 12 Nov 2025 21:33:18 +0100 Subject: [PATCH] Clarified meaning of process_state.requesting_thread (the now-removed 'treat as pid' was hallunicated by the bot; the taken-from-sentry version missed the guard against -1) > The index of the thread that requested a dump be written in the > threads vector. [..] If the dump was not produced as a result of an exception > [..] this field will be set to -1, --- files/minidump.py | 4 ++-- sentry/minidump.py | 42 +++++++++++++++++++----------------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/files/minidump.py b/files/minidump.py index 2ac523c..9739454 100644 --- a/files/minidump.py +++ b/files/minidump.py @@ -88,7 +88,7 @@ def _find_module_for_address(process_state, abs_addr: int): def event_threads_for_process_state(process_state): threads = [] - for thread in process_state.threads(): + for thread_index, thread in enumerate(process_state.threads()): thread_frames = [] for frame in thread.frames(): @@ -136,7 +136,7 @@ def event_threads_for_process_state(process_state): threads.append({ "id": thread.thread_id, - "crashed": (thread.thread_id == process_state.requesting_thread), + "crashed": thread_index == process_state.requesting_thread, "stacktrace": {"frames": thread_frames}, }) diff --git a/sentry/minidump.py b/sentry/minidump.py index abf40c4..3322649 100644 --- a/sentry/minidump.py +++ b/sentry/minidump.py @@ -29,34 +29,30 @@ def merge_minidump_event(data, minidump_bytes): threads = event_threads_for_process_state(process_state) data.setdefault("threads", {})["values"] = threads - # Mark the crashed thread and add its stacktrace to the exception - crashed_thread = threads[process_state.requesting_thread] - crashed_thread['crashed'] = True + if process_state.requesting_thread > -1: + crashed_thread = threads[process_state.requesting_thread] - exception_value = 'Assertion Error: %s' % process_state.assertion if process_state.assertion \ - else 'Fatal Error: %s' %process_state.crash_reason + exception_value = 'Assertion Error: %s' % process_state.assertion if process_state.assertion \ + else 'Fatal Error: %s' % process_state.crash_reason - # Extract the crash reason and infos - exception = { - 'value': exception_value, - 'thread_id': crashed_thread['id'], - 'type': process_state.crash_reason, + exception = { + 'value': exception_value, + 'thread_id': crashed_thread['id'], + 'type': process_state.crash_reason, + 'stacktrace': crashed_thread.pop('stacktrace'), + 'value': exception_value, + } - # Move stacktrace here from crashed_thread (mutating!) - 'stacktrace': crashed_thread.pop('stacktrace'), - 'value': exception_value, - } + for frame in exception['stacktrace']['frames']: + frame['in_app'] = True # minidumps don't distinguish in_app frames; assume all are in_app - for frame in exception['stacktrace']['frames']: - frame['in_app'] = True # minidumps don't distinguish in_app frames; assume all are in_app + exception['stacktrace']['frames'].reverse() # "Frames should be sorted from oldest to newest." + # TODO we don't have display-info for threads yet, I think? + # we may need to revert the per-thread stacktraces above as well then - exception['stacktrace']['frames'].reverse() # "Frames should be sorted from oldest to newest." - # TODO we don't have display-info for threads yet, I think? - # we may need to revert the per-thread stacktraces above as well then - - data.setdefault('exception', {}) \ - .setdefault('values', []) \ - .append(exception) + data.setdefault('exception', {}) \ + .setdefault('values', []) \ + .append(exception) # Extract referenced (not all loaded) images images = [{