code: def dump_exception(
      data_transferer, exception_type, exception_val, tb, user_data=None
  ):
      if (
          exception_type is StopIteration
      ):  # Very common exception so we encode quickly
          return data_transferer.dump({FIELD_EXC_SI: True})
      local_formatted_exception = "".join(
          traceback.format_exception(exception_type, exception_val, tb)
      )
      exception_args = []
      exception_attrs = []
      str_repr = None
      repr_repr = None
      for name in dir(exception_val):
          if name == "args":
              # Handle arguments specifically to try to get all arguments even if
              # some require repr
              for arg in exception_val.args:
                  if DataTransferer.can_simple_dump(arg):
                      exception_args.append(arg)
                  else:
                      exception_args.append(repr(arg))
          elif name == "__str__":
              str_repr = str(exception_val)
          elif name == "__repr__":
              repr_repr = repr(exception_val)
          elif name.startswith("_") or name == "with_traceback":
              continue
          else:
              try:
                  attr = getattr(exception_val, name)
              except AttributeError:
                  continue
              if DataTransferer.can_simple_dump(attr):
                  exception_attrs.append((name, attr))
              else:
                  exception_attrs.append((name, repr(attr)))
      to_return = {
          FIELD_EXC_MODULE: exception_type.__module__,
          FIELD_EXC_NAME: exception_type.__name__,
          FIELD_EXC_ARGS: exception_args,
          FIELD_EXC_ATTR: exception_attrs,
          FIELD_EXC_TB: local_formatted_exception,
          FIELD_EXC_STR: str_repr,
          FIELD_EXC_REPR: repr_repr,
      }
      if user_data is not None:
          if DataTransferer.can_simple_dump(user_data):
              to_return[FIELD_EXC_USER] = user_data
          else:
              to_return[FIELD_EXC_USER] = repr(user_data)
      return data_transferer.dump(to_return)
  
imports: import sys
  import traceback
label_desc: Use image node_id 1 for calling a global function with example usage: dump_exception(data_transferer, exception_type, exception_val, tb, user_data) and returns: data_transferer, data_transferer