@@ -1870,28 +1870,36 @@ def _enhanced_stack_trace(self) -> temporalio.api.sdk.v1.EnhancedStackTrace:
18701870
18711871 # this is to use `open`
18721872 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.
18751878
18761879 for task in list (self ._tasks ):
1877- locations = []
1880+ locations : List [temporalio .api .sdk .v1 .StackTraceFileLocation ] = []
1881+
18781882 for frame in task .get_stack ():
18791883 filename = frame .f_code .co_filename
18801884 line_number = frame .f_lineno
18811885 func_name = frame .f_code .co_name
18821886
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+
18951903 file_location = temporalio .api .sdk .v1 .StackTraceFileLocation (
18961904 file_path = filename ,
18971905 line = line_number ,
@@ -1900,7 +1908,6 @@ def _enhanced_stack_trace(self) -> temporalio.api.sdk.v1.EnhancedStackTrace:
19001908 internal_code = False ,
19011909 )
19021910
1903- sources [filename ] = file_slice
19041911 locations .append (file_location )
19051912
19061913 stacks .append (temporalio .api .sdk .v1 .StackTrace (locations = locations ))
0 commit comments