tools: Improve error handling.