title: To what extent are errors strings guaranteed to not change?
body: <p>One of the main issues I have with Golang is that the error handling is basically a check for a string (I would love to be wrong, do not hesitate :))</p>
  <p>In the example below, I am trying to create a directory, but will have different behaviour depending on the kind of issue. Specifically, if a directory exists I will just pass.</p>
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      &quot;fmt&quot;
      &quot;os&quot;
  )
  
  func main() {
      err := os.Mkdir(&quot;test&quot;, 0644)
      if err != nil {
          fmt.Printf(&quot;error: %v&quot;, err)
          if err.Error() == &quot;mkdir test: Cannot create a file when that file already exists&quot; {
              fmt.Printf(&quot;the dir already exists&quot;)
          } else {
              panic(err)
          }
      }
  }
  </code></pre>
  <p>It does not work, repeated attempts are not logged. Why? Ah, crap, I forgot the dot at the end of the <code>mkdir test: Cannot create a file when that file already exists</code> string.</p>
  <p>I feel that relying on an error string is fragile, as opposed to having something like <code>err.ErrorType().DirectoryExists()</code> kind of check (which sometimes exists, in <code>net</code> for instance).</p>
  <p><strong>My question: to what extent can I rely on the fact that the error strings will not change?</strong> (in other words, that <code>mkdir test: Cannot create a file when that file already exists.</code> will not be worded differently, or ported to another national language, etc.)</p>
  <p>I had some hope with <code>errors.Is()</code> but it ultimately relies on the string comparison.</p>