File validation and error handling