Back to all reviewers

Clear recoverable error messages

ollama/ollama
Based on 5 comments
Go

Error messages should be clear, actionable, and indicate whether recovery is possible. When designing error handling: 1. Use descriptive messages that explain what went wrong and how to fix it

Error Handling Go

Reviewer Prompt

Error messages should be clear, actionable, and indicate whether recovery is possible. When designing error handling:

  1. Use descriptive messages that explain what went wrong and how to fix it
  2. Indicate if the error is expected/recoverable
  3. Provide appropriate fallbacks when safe
  4. Include relevant context in error messages

Example:

// Instead of
if err != nil {
    return fmt.Errorf("puller failed: %w", err)
}

// Do this
if err != nil {
    if errors.Is(err, ErrModelNotFound) {
        // Clear message with actionable hint
        return fmt.Errorf("model %q not found - check available models at: https://ollama.com/models", name)
    }
    // Indicate if retry may help
    if isTemporary(err) {
        return fmt.Errorf("temporary error fetching model %q, retry may resolve: %w", name, err)
    }
    return fmt.Errorf("failed to pull model %q: %w", name, err)
}

// Consider fallbacks for non-critical errors
if req.Options == nil {
    // Use safe defaults instead of error
    req.Options = api.DefaultOptions()
}

This approach helps users understand and recover from errors while maintaining system stability through appropriate fallbacks.

5
Comments Analyzed
Go
Primary Language
Error Handling
Category

Source Discussions