refactor(errorsx): prepare for splitting the package (#476)

We will move the sane part of this package to i/netxlite/errorsx
and we will move the rest to i/e/legacy/errorsx.

What is the sane part? The sane part is error classifiers plus
the definition of ErrWrapper. The rest, including the rules
on how to decide whether an operation is major, are tricky and
we should consider them legacy and replace them with rules
that are more easy to understand and reason on.

Part of https://github.com/ooni/probe/issues/1591
This commit is contained in:
Simone Basso 2021-09-07 15:46:32 +02:00 committed by GitHub
commit ccb3a644e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 96 additions and 90 deletions

View file

@ -88,7 +88,7 @@ func (d *ErrorWrapperQUICDialer) DialContext(
tlsCfg *tls.Config, cfg *quic.Config) (quic.EarlySession, error) {
sess, err := d.Dialer.DialContext(ctx, network, host, tlsCfg, cfg)
err = SafeErrWrapperBuilder{
Classifier: classifyQUICFailure,
Classifier: ClassifyQUICHandshakeError,
Error: err,
Operation: QUICHandshakeOperation,
}.MaybeBuild()
@ -98,8 +98,9 @@ func (d *ErrorWrapperQUICDialer) DialContext(
return sess, nil
}
// classifyQUICFailure is a classifier to translate QUIC errors to OONI error strings.
func classifyQUICFailure(err error) string {
// ClassifyQUICHandshakeError maps an error occurred during the QUIC
// handshake to an OONI failure string.
func ClassifyQUICHandshakeError(err error) string {
var versionNegotiation *quic.VersionNegotiationError
var statelessReset *quic.StatelessResetError
var handshakeTimeout *quic.HandshakeTimeoutError
@ -139,7 +140,7 @@ func classifyQUICFailure(err error) string {
return FailureSSLInvalidHostname
}
}
return toFailureString(err)
return ClassifyGenericError(err)
}
// TLS alert protocol as defined in RFC8446