包的所有方法以Go语言返回的错误列表

Is there an easy way to know about all errors that methods of a package in Go return?

For example, the net package returns several error types such as AddrError, DNSConfigError, DNSError, and so on. These error types are declared in the net package. However, the net package also returns os.PathError, syscall.* errors, which are errors declared in other packages, in its methods.

I want to categorize all error types the net package returns, and do something for each of these errors as well as writing log message. But, I noticed that http://golang.org/pkg/ site does not provide these returning error types like "ERRORS" sections in http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html page.

Please let me know if there is a way to know these information.

Thanks.

You would have to write something that:

  1. Parse the package, list all obvious errors (anything that defines Error() string).
  2. Parse all functions that returns error and check all their return paths.

You can look into using go/ast and go/parser.