Prompt
Error messages should provide clear, actionable information that helps users understand and resolve the problem. Each error should:
- Include specific context about what failed
- Explain why it failed
- When applicable, suggest how to fix it
Example of improving error messages:
// Instead of:
#[error(transparent)]
ManagedPythonError(#[from] managed::Error),
// Prefer:
#[error("Failed to discover managed Python installations")]
ManagedPythonError(#[from] managed::Error),
// Even better with context and remedy:
#[error("Failed to authenticate with {url}")]
#[error("hint: Check your credentials or configure authentication using UV_INDEX_{index}_USERNAME")]
AuthenticationError { url: String, index: String }
When designing error handling:
- Use specific error variants instead of returning Ok(None) for expected failure cases
- Include relevant context (URLs, file paths, version numbers) in error messages
- Add hints or help messages for common failure scenarios
- Distinguish between different failure modes (e.g., missing vs invalid credentials)
- Keep error messages focused on the user’s perspective rather than internal implementation details