golang package for enhanced errors that capture file and line number information, the call stack, relevant identifiers, and a handle back to the original error for type switching.
Replacement for fmt.Errorf(...):
err := errors.Errorf("Failed to do something; here's a value %v",len(data))
fmt.Printf("%#v\n",err) // Prints full stack trace.
Wrap another function's error:
_, err := net.Dial( "tcp", "localhost:8080" )
if err != nil {
return errors.Go( err )
}
Obtain the original error in order to type switch:
func connect() error {
_, err := net.Dial( "tcp", "localhost:0" )
if err != nil {
return errors.Go( err )
}
return nil
}
err := connect()
switch errors.Original( err ).(type) {
case *net.OpError:
// We know the original type!
}
See the godoc link for more information.