Add error handling for invalid paths