Functions should raise exceptions with meaningful messages instead of returning False, None, or silently catching all exceptions. This allows calling code to properly understand what went wrong and take appropriate action.
Functions should raise exceptions with meaningful messages instead of returning False, None, or silently catching all exceptions. This allows calling code to properly understand what went wrong and take appropriate action.
Key principles:
Example of problematic pattern:
def path_is_low_integrity_writable(path):
result = subprocess.run([ICACLS_PATH, path], capture_output=True, text=True)
if result.returncode != 0:
# Silent failure - calling code doesn't know what went wrong
return False
return does_permit_low_integrity_write(result.stdout)
Improved approach:
def path_is_low_integrity_writable(path):
result = subprocess.run([ICACLS_PATH, path], capture_output=True, text=True)
if result.returncode != 0:
raise PermissionError(f"Failed to check ACL for path {path}: {result.stderr}")
return does_permit_low_integrity_write(result.stdout)
Additional considerations:
Enter the URL of a public GitHub repository