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:
parent
cef801fa23
commit
ccb3a644e1
11 changed files with 96 additions and 90 deletions
|
|
@ -25,15 +25,16 @@ func (h *ErrorWrapperTLSHandshaker) Handshake(
|
|||
) (net.Conn, tls.ConnectionState, error) {
|
||||
tlsconn, state, err := h.TLSHandshaker.Handshake(ctx, conn, config)
|
||||
err = SafeErrWrapperBuilder{
|
||||
Classifier: classifyTLSFailure,
|
||||
Classifier: ClassifyTLSHandshakeError,
|
||||
Error: err,
|
||||
Operation: TLSHandshakeOperation,
|
||||
}.MaybeBuild()
|
||||
return tlsconn, state, err
|
||||
}
|
||||
|
||||
// classifyTLSFailure is a classifier to translate TLS errors to OONI error strings.
|
||||
func classifyTLSFailure(err error) string {
|
||||
// ClassifyTLSHandshakeError maps an error occurred during the TLS
|
||||
// handshake to an OONI failure string.
|
||||
func ClassifyTLSHandshakeError(err error) string {
|
||||
var x509HostnameError x509.HostnameError
|
||||
if errors.As(err, &x509HostnameError) {
|
||||
// Test case: https://wrong.host.badssl.com/
|
||||
|
|
@ -50,5 +51,5 @@ func classifyTLSFailure(err error) string {
|
|||
// Test case: https://expired.badssl.com/
|
||||
return FailureSSLInvalidCertificate
|
||||
}
|
||||
return toFailureString(err)
|
||||
return ClassifyGenericError(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue