code: def dump_traceback_code(
      tb: types.TracebackType, number_of_lines_of_context: int = 5
  ):
      """
      Dump codes before and after lines of tracebacks.
  
      Parameters
      ----------
      tb: types.TracebackType
          Traceback object
      number_of_lines_of_context: int
          Total number of lines around the code
      Returns
      -------
      result: dict
          Dumped code lines of traceback
      """
      results = defaultdict(lambda: dict(fragments=[]))
  
      while tb:
          file_name = tb.tb_frame.f_code.co_filename
          if linecache.getline(
              file_name, tb.tb_lineno
          ):  # pragma: no branch
              code_lines = linecache.cache[file_name][2]
              left_range = max(
                  tb.tb_lineno - number_of_lines_of_context // 2 - 1, 0
              )
              right_range = min(
                  left_range + number_of_lines_of_context,
                  len(code_lines),
              )
  
              cache_data = linecache.cache[file_name]
              fragment = cache_data[2][left_range:right_range]
              results[file_name]["fragments"].append(
                  dict(
                      left=left_range, right=right_range, code=fragment
                  )
              )
              results[file_name].update(
                  dict(size=cache_data[0], lines=len(cache_data[2]))
              )
          tb = tb.tb_next
      return dict(results)
  
imports: import linecache
  import os
  import types
  from collections import defaultdict
label_desc: Use image node_id 1 for calling a global function with example usage: dump_traceback_code(tb, number_of_lines_of_context) and returns: dict