I was reading the error handling of a Go email verifier on a Saturday, and one function stopped me halfway down the file:
func parseBasicErr ( err error ) error { re := err . Error ( ) switch { case strings . Contains ( re , "timeout" ) : return ErrTimeout case strings . Contains ( re , "no such host" ) : return ErrNoSuchHost case strings . Contains ( re , "unavailable" ) : return ErrServerUnavailable } return LookupError { Message : re } }
Enter fullscreen mode
Exit fullscreen mode
Three substrings decide what happened to a DNS lookup. That is the whole classifier.
Then I hit the case that breaks it. A resolver returning SERVFAIL does not say "timeout" and does not say "no such host". It says this, verbatim:
lookup example.com on 127.0.0.11:53: server misbehaving
Enter fullscreen mode
Exit fullscreen mode
Zero hits. It falls straight through to the default, and the raw Go string becomes the value the rest of the library switches on.…