title: Returning an optional value and an error
body: <p>What's the best signature for a function that returns an optional value and a possible error?</p>
  
  <p>For example:</p>
  
  <pre><code>func findColor(name string) (RGB, error) {
      ...
  }
  </code></pre>
  
  <p>(The empty RGB value is black, a valid color, so you can't use it to infer that no value was found. Assume the error might come from something like a database connection.)</p>
  
  <p>The two options that seem best are a boolean return value:</p>
  
  <pre><code>func findColor(name string) (RGB, bool, error) {
      ...
  }
  
  c, ok, err := findColor(myname)
  
  if !ok {
      ...
  } else if err != nil {
      ...
  }
  
  ...
  </code></pre>
  
  <p>Or a special error value:</p>
  
  <pre><code>var ColorNotFound = errors.New(...)
  
  func findColor(name string) (RGB, error) {
      ...
  }
  
  c, err := findColor(...)
  
  if err == ColorNotFound {
      ...
  } else if err != nil {
      ...
  }
  
  ...
  </code></pre>
  
  <p>(Making special errors seems like a pain.)</p>
  
  <p>What's the most idiomatic approach?</p>