code: def handle_exception(
      handler: Handler | CodeRunner, e: Exception
  ) -> None:
      """Record an exception and details on a Handler."""
      handler._failed = True
      handler._error_detail = traceback.format_exc()
  
      _, _, exc_traceback = sys.exc_info()
      filename, line_number, func, txt = traceback.extract_tb(
          exc_traceback
      )[-1]
  
      basename = os.path.basename(filename)
      handler._error = f"{e}\nFile {basename!r}, line {line_number}, in {func}:\n{txt}"
  
imports: from __future__ import annotations
  import logging
  import os
  import sys
  import traceback
  from typing import TYPE_CHECKING, Any
  from ...document import Document
  from ..application import ServerContext, SessionContext
label_desc: Use image node_id 1 for calling a global function with example usage: handle_exception(handler, e) without return types