def to_repr(obj: Any) -> str:
    'Get repr string for an object, but catch errors.'
    if ((max_string is not None) and isinstance(obj, (bytes, str)) and (len(obj) > max_string)):
        truncated = (len(obj) - max_string)
        obj_repr = f'{obj[:max_string]!r}+{truncated}'
    else:
        try:
            obj_repr = repr(obj)
        except Exception as error:
            obj_repr = f"<repr-error '{error}'>"
    return obj_repr
Get repr string for an object, but catch errors.
def to_repr(obj: Any) -> str:
    
    if ((max_string is not None) and isinstance(obj, (bytes, str)) and (len(obj) > max_string)):
        truncated = (len(obj) - max_string)
        obj_repr = f'{obj[:max_string]!r}+{truncated}'
    else:
        try:
            obj_repr = repr(obj)
        except Exception as error:
            obj_repr = f"<repr-error '{error}'>"
    return obj_repr