```python
def line_tag(body: str) -> str:
    if not isinstance(body, str):
        raise ValueError("line_tag expects a string")
    return format(sum(ord(ch) for ch in body) % 256, "02x")

def check_line(line: str) -> str:
    if not isinstance(line, str) or len(line) < 3:
        raise ValueError("check_line expects a non-empty string with at least three characters")
    if line[2] != '~':
        raise ValueError("The third character must be a tilde (~)")
    
    body = line[:-3]
    tag = line[-2:]
    calculated_tag = line_tag(body)
    
    if tag != calculated_tag:
        raise ValueError("The tag does not match the body")
    
    return body
```