]> Cypherpunks repositories - gostls13.git/commitdiff
doc/effective_go: add a note about prefixing error strings with their
authorNigel Tao <nigeltao@golang.org>
Fri, 17 Jun 2011 00:51:10 +0000 (10:51 +1000)
committerNigel Tao <nigeltao@golang.org>
Fri, 17 Jun 2011 00:51:10 +0000 (10:51 +1000)
package name.

R=r, rsc
CC=golang-dev
https://golang.org/cl/4630042

doc/effective_go.html

index 0f9b70729e22cf2439aee18429374af196107e46..9a674c72bfea8380c7399a17fb24c659f4de3c7d 100644 (file)
@@ -233,9 +233,9 @@ Since the whole declaration is presented, such a comment can often be perfunctor
 <pre>
 // Error codes returned by failures to parse an expression.
 var (
-    ErrInternal      = os.NewError("internal error")
-    ErrUnmatchedLpar = os.NewError("unmatched '('")
-    ErrUnmatchedRpar = os.NewError("unmatched ')'")
+    ErrInternal      = os.NewError("regexp: internal error")
+    ErrUnmatchedLpar = os.NewError("regexp: unmatched '('")
+    ErrUnmatchedRpar = os.NewError("regexp: unmatched ')'")
     ...
 )
 </pre>
@@ -2673,6 +2673,13 @@ it is much more informative than the plain
 "no such file or directory".
 </p>
 
+<p>
+When feasible, error strings should identify their origin, such as by having
+a prefix naming the package that generated the error.  For example, in package
+image, the string representation for a decoding error due to an unknown format
+is "image: unknown format".
+</p>
+
 <p>
 Callers that care about the precise error details can
 use a type switch or a type assertion to look for specific