@@ -816,38 +816,7 @@ def single_exception_from_error_tuple(
816816 if not full_stack :
817817 new_frames = frames
818818 else :
819- # Add the missing frames from full_stack
820- frame_ids = {
821- (
822- frame ["abs_path" ],
823- frame ["context_line" ],
824- frame ["lineno" ],
825- frame ["function" ],
826- )
827- for frame in frames
828- }
829-
830- new_frames = [
831- stackframe
832- for stackframe in full_stack
833- if (
834- stackframe ["abs_path" ],
835- stackframe ["context_line" ],
836- stackframe ["lineno" ],
837- stackframe ["function" ],
838- )
839- not in frame_ids
840- ]
841- new_frames .extend (frames )
842-
843- # Limit the number of frames
844- max_stack_frames = (
845- client_options .get ("max_stack_frames" , DEFAULT_MAX_STACK_FRAMES )
846- if client_options
847- else None
848- )
849- if max_stack_frames is not None :
850- new_frames = new_frames [:max_stack_frames ]
819+ new_frames = merge_stack_frames (frames , full_stack , client_options )
851820
852821 exception_value ["stacktrace" ] = {"frames" : new_frames }
853822
@@ -1177,6 +1146,46 @@ def get_full_stack():
11771146 return stack_info
11781147
11791148
1149+ def merge_stack_frames (frames , full_stack , client_options ):
1150+ # type: (List[Dict[str, Any]], List[Dict[str, Any]], Optional[Dict[str, Any]]) -> List[Dict[str, Any]]
1151+ """
1152+ Add the missing frames from full_stack to frames and return the merged list.
1153+ """
1154+ frame_ids = {
1155+ (
1156+ frame ["abs_path" ],
1157+ frame ["context_line" ],
1158+ frame ["lineno" ],
1159+ frame ["function" ],
1160+ )
1161+ for frame in frames
1162+ }
1163+
1164+ new_frames = [
1165+ stackframe
1166+ for stackframe in full_stack
1167+ if (
1168+ stackframe ["abs_path" ],
1169+ stackframe ["context_line" ],
1170+ stackframe ["lineno" ],
1171+ stackframe ["function" ],
1172+ )
1173+ not in frame_ids
1174+ ]
1175+ new_frames .extend (frames )
1176+
1177+ # Limit the number of frames
1178+ max_stack_frames = (
1179+ client_options .get ("max_stack_frames" , DEFAULT_MAX_STACK_FRAMES )
1180+ if client_options
1181+ else None
1182+ )
1183+ if max_stack_frames is not None :
1184+ new_frames = new_frames [:max_stack_frames ]
1185+
1186+ return new_frames
1187+
1188+
11801189def event_from_exception (
11811190 exc_info , # type: Union[BaseException, ExcInfo]
11821191 client_options = None , # type: Optional[Dict[str, Any]]
0 commit comments