Rather than using a boolean and raising at the end, why not raise in each of the `if` blocks? That way, you can provide more context in the error message for *why* the file name is unsafe.