@@ -54,14 +54,15 @@ class NeedsExtension(Exception):
54
54
def derive_code_mappings (
55
55
organization : Organization ,
56
56
frame : Mapping [str , Any ],
57
+ platform : str | None = None ,
57
58
) -> list [dict [str , str ]]:
58
59
installation = get_installation (organization )
59
60
if not isinstance (installation , RepoTreesIntegration ):
60
61
return []
61
62
trees = installation .get_trees_for_org ()
62
63
trees_helper = CodeMappingTreesHelper (trees )
63
64
try :
64
- frame_filename = FrameInfo (frame )
65
+ frame_filename = FrameInfo (frame , platform )
65
66
return trees_helper .list_file_matches (frame_filename )
66
67
except NeedsExtension :
67
68
logger .warning ("Needs extension: %s" , frame .get ("filename" ))
@@ -71,8 +72,8 @@ def derive_code_mappings(
71
72
72
73
# XXX: Look at sentry.interfaces.stacktrace and maybe use that
73
74
class FrameInfo :
74
- def __init__ (self , frame : Mapping [str , Any ]) -> None :
75
- # XXX: In the next PR, we will use more than just the filename
75
+ def __init__ (self , frame : Mapping [str , Any ], platform : str | None = None ) -> None :
76
+ # XXX: platform will be used in a following PR
76
77
frame_file_path = frame ["filename" ]
77
78
frame_file_path = self .transformations (frame_file_path )
78
79
@@ -102,11 +103,13 @@ def __init__(self, frame: Mapping[str, Any]) -> None:
102
103
103
104
def transformations (self , frame_file_path : str ) -> str :
104
105
self .raw_path = frame_file_path
106
+
105
107
is_windows_path = False
106
108
if "\\ " in frame_file_path :
107
109
is_windows_path = True
108
110
frame_file_path = frame_file_path .replace ("\\ " , "/" )
109
111
112
+ # Remove leading slash if it exists
110
113
if frame_file_path [0 ] == "/" or frame_file_path [0 ] == "\\ " :
111
114
frame_file_path = frame_file_path [1 :]
112
115
@@ -131,15 +134,21 @@ def __eq__(self, other: object) -> bool:
131
134
132
135
# call generate_code_mappings() after you initialize CodeMappingTreesHelper
133
136
class CodeMappingTreesHelper :
137
+ platform : str | None = None
138
+
134
139
def __init__ (self , trees : Mapping [str , RepoTree ]):
135
140
self .trees = trees
136
141
self .code_mappings : dict [str , CodeMapping ] = {}
137
142
138
- def generate_code_mappings (self , frames : Sequence [Mapping [str , Any ]]) -> list [CodeMapping ]:
143
+ def generate_code_mappings (
144
+ self , frames : Sequence [Mapping [str , Any ]], platform : str | None = None
145
+ ) -> list [CodeMapping ]:
139
146
"""Generate code mappings based on the initial trees object and the list of stack traces"""
140
147
# We need to make sure that calling this method with a new list of stack traces
141
148
# should always start with a clean slate
142
149
self .code_mappings = {}
150
+ self .platform = platform
151
+
143
152
buckets : dict [str , list [FrameInfo ]] = self ._stacktrace_buckets (frames )
144
153
145
154
# We reprocess stackframes until we are told that no code mappings were produced
@@ -200,7 +209,7 @@ def _stacktrace_buckets(
200
209
buckets : defaultdict [str , list [FrameInfo ]] = defaultdict (list )
201
210
for frame in frames :
202
211
try :
203
- frame_filename = FrameInfo (frame )
212
+ frame_filename = FrameInfo (frame , self . platform )
204
213
# Any files without a top directory will be grouped together
205
214
buckets [frame_filename .stack_root ].append (frame_filename )
206
215
except UnsupportedFrameInfo :
0 commit comments