def METHOD_NAME(err):
    if not err:
        return ""
    if isinstance(err, str):
        return err
    errors = []
    error_strings = []
    while err and err not in errors:
        errors.append(err)
        err_msg = str(err)
        if not err_msg:
            err_msg = repr(err)
        error_strings.append(err_msg)
        err = err.__cause__
    return ", caused by: ".join(error_strings)