@@ -1870,28 +1870,36 @@ def _enhanced_stack_trace(self) -> temporalio.api.sdk.v1.EnhancedStackTrace:
1870
1870
1871
1871
# this is to use `open`
1872
1872
with temporalio .workflow .unsafe .sandbox_unrestricted ():
1873
- sources = dict ()
1874
- stacks = []
1873
+ sources : Dict [str , temporalio .api .sdk .v1 .StackTraceFileSlice ] = dict ()
1874
+ stacks : List [temporalio .api .sdk .v1 .StackTrace ] = []
1875
+
1876
+ # future TODO
1877
+ # site package filter list -- we want to filter out traces from Python's internals and our sdk's internals. This is what `internal_code` is for, but right now it's just set to false.
1875
1878
1876
1879
for task in list (self ._tasks ):
1877
- locations = []
1880
+ locations : List [temporalio .api .sdk .v1 .StackTraceFileLocation ] = []
1881
+
1878
1882
for frame in task .get_stack ():
1879
1883
filename = frame .f_code .co_filename
1880
1884
line_number = frame .f_lineno
1881
1885
func_name = frame .f_code .co_name
1882
1886
1883
- try :
1884
- with open (filename , "r" ) as f :
1885
- code = f .read ()
1886
- except OSError as ose :
1887
- code = f"Cannot access code.\n ---\n { ose .strerror } "
1888
- # TODO possibly include sentinel/property for success of src scrape? work out with ui
1889
- except Exception :
1890
- code = f"Generic Error.\n \n { traceback .format_exc ()} "
1891
-
1892
- file_slice = temporalio .api .sdk .v1 .StackTraceFileSlice (
1893
- line_offset = 0 , content = code
1894
- )
1887
+ if filename not in sources .keys ():
1888
+ try :
1889
+ with open (filename , "r" ) as f :
1890
+ code = f .read ()
1891
+ except OSError as ose :
1892
+ code = f"Cannot access code.\n ---\n { ose .strerror } "
1893
+ # TODO possibly include sentinel/property for success of src scrape? work out with ui
1894
+ except Exception :
1895
+ code = f"Generic Error.\n \n { traceback .format_exc ()} "
1896
+
1897
+ file_slice = temporalio .api .sdk .v1 .StackTraceFileSlice (
1898
+ line_offset = 0 , content = code
1899
+ )
1900
+
1901
+ sources [filename ] = file_slice
1902
+
1895
1903
file_location = temporalio .api .sdk .v1 .StackTraceFileLocation (
1896
1904
file_path = filename ,
1897
1905
line = line_number ,
@@ -1900,7 +1908,6 @@ def _enhanced_stack_trace(self) -> temporalio.api.sdk.v1.EnhancedStackTrace:
1900
1908
internal_code = False ,
1901
1909
)
1902
1910
1903
- sources [filename ] = file_slice
1904
1911
locations .append (file_location )
1905
1912
1906
1913
stacks .append (temporalio .api .sdk .v1 .StackTrace (locations = locations ))
0 commit comments