Error handling for port selection