from typing import Any


def safe_str(x: Any) -> str:
    """Useful utility in place of str() to handle None and other errors in logging without breaking the program."""
    try:
        if x is None:
            return 'None'
        if isinstance(x, BaseException):
            return repr(x)
        return str(x)
    except Exception as ex:
        return '<ERROR>: ' + str(ex)