*,
    task_instance: TaskInstance | TaskInstancePydantic,
    error: None | str | Exception | KeyboardInterrupt,
    session: Session,
    test_mode: bool | None = None,
    context: Context | None = None,
    force_fail: bool = False,
) -> None:
    """
    Handle Failure for a task instance.
    :param task_instance: the task instance
    :param error: if specified, log the specific exception if thrown
    :param session: SQLAlchemy ORM Session
    :param test_mode: doesn't record success or failure in the DB if True
    :param context: Jinja2 context
    :param force_fail: if True, task does not retry
    :meta private:
    """
    if test_mode is None:
        test_mode = task_instance.test_mode
    failure_context = TaskInstance.fetch_handle_failure_context(
        ti=task_instance,
        error=error,
        test_mode=test_mode,
        context=context,
        force_fail=force_fail,
        session=session,
    )