```python
def trim_caption(text: str, limit: int) -> str:
    if not isinstance(text, str):
        raise ValueError("Text must be a string")
    if not isinstance(limit, int) or limit <= 0:
        raise ValueError("Limit must be a positive whole number")

    text = text.strip()
    if len(text) <= limit:
        return text

    # Find the last space before the limit-1 character
    for i in range(limit - 2, -1, -1):
        if text[i] == ' ':
            break

    # If no space is found, cut off at the limit-1 character
    if i == -1:
        return text[:limit]

    # Cut off at the last space before the limit-1 character
    return text[:i + 1] + "…"
```