Improved error handling by checking path exists before open