code: def report_crash(node, traceback=None, hostname=None):
      """Writes crash related information to a file"""
      name = node._id
      host = None
      traceback = traceback or format_exception(*sys.exc_info())
  
      try:
          result = node.result
      except FileNotFoundError:
          traceback += """
  
  When creating this crashfile, the results file corresponding
  to the node could not be found.""".splitlines(
              keepends=True
          )
      except Exception as exc:
          traceback += """
  
  During the creation of this crashfile triggered by the above exception,
  another exception occurred:\n\n{}.""".format(
              exc
          ).splitlines(
              keepends=True
          )
      else:
          if getattr(result, "runtime", None):
              if isinstance(result.runtime, list):
                  host = result.runtime[0].hostname
              else:
                  host = result.runtime.hostname
  
      # Try everything to fill in the host
      host = host or hostname or gethostname()
      logger.error("Node %s failed to run on host %s.", name, host)
      timeofcrash = strftime("%Y%m%d-%H%M%S")
      try:
          login_name = getpass.getuser()
      except KeyError:
          login_name = f"UID{os.getuid():d}"
      crashfile = (
          f"crash-{timeofcrash}-{login_name}-{name}-{str(uuid.uuid4())}"
      )
      crashdir = node.config["execution"].get(
          "crashdump_dir", os.getcwd()
      )
  
      os.makedirs(crashdir, exist_ok=True)
      crashfile = os.path.join(crashdir, crashfile)
  
      if node.config["execution"]["crashfile_format"].lower() in (
          "text",
          "txt",
          ".txt",
      ):
          crashfile += ".txt"
      else:
          crashfile += ".pklz"
  
      logger.error(
          "Saving crash info to %s\n%s", crashfile, "".join(traceback)
      )
      if crashfile.endswith(".txt"):
          crash2txt(crashfile, dict(node=node, traceback=traceback))
      else:
          savepkl(
              crashfile,
              dict(node=node, traceback=traceback),
              versioning=True,
          )
      return crashfile
  
file_path: nipype/nipype/pipeline/plugins/tools.py
imports: import os
  import getpass
  from socket import gethostname
  import sys
  import uuid
  from time import strftime
  from traceback import format_exception
  from ...None import logging
  from ...utils.filemanip import savepkl, crash2txt
label_desc: Use image node_id 1 for calling a global function with example usage: report_crash(node, traceback, hostname) and returns: crashfile