refactor(errorsx): start hiding private details and moving around stuff (#424)

* refactor(errorsx): start hiding private details and moving around stuff

Part of https://github.com/ooni/probe/issues/1505

* fix: remove now-addressed todo comments
This commit is contained in:
Simone Basso 2021-07-02 11:35:00 +02:00 committed by GitHub
commit 17bfb052c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 235 additions and 236 deletions

View file

@ -1,6 +1,9 @@
package errorsx
import "context"
import (
"context"
"errors"
)
// Resolver is a DNS resolver. The *net.Resolver used by Go implements
// this interface, but other implementations are possible.
@ -20,13 +23,21 @@ var _ Resolver = &ErrorWrapperResolver{}
func (r *ErrorWrapperResolver) LookupHost(ctx context.Context, hostname string) ([]string, error) {
addrs, err := r.Resolver.LookupHost(ctx, hostname)
err = SafeErrWrapperBuilder{
Classifier: ClassifyResolveFailure,
Classifier: classifyResolveFailure,
Error: err,
Operation: ResolveOperation,
}.MaybeBuild()
return addrs, err
}
// classifyResolveFailure is a classifier to translate DNS resolving errors to OONI error strings.
func classifyResolveFailure(err error) string {
if errors.Is(err, ErrDNSBogon) {
return FailureDNSBogonError // not in MK
}
return toFailureString(err)
}
type resolverNetworker interface {
Network() string
}