Handling invalid URIs with grace