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
|
|
@ -85,7 +85,7 @@ func (b SafeErrWrapperBuilder) MaybeBuild() (err error) {
|
|||
if b.Error != nil {
|
||||
classifier := b.Classifier
|
||||
if classifier == nil {
|
||||
classifier = toFailureString
|
||||
classifier = ClassifyGenericError
|
||||
}
|
||||
err = &ErrWrapper{
|
||||
Failure: classifier(b.Error),
|
||||
|
|
@ -100,7 +100,10 @@ func (b SafeErrWrapperBuilder) MaybeBuild() (err error) {
|
|||
// Use errors.Is / errors.As more often, when possible, in this classifier.
|
||||
// These methods are more robust to library changes than strings.
|
||||
// errors.Is / errors.As can only be used when the error is exported.
|
||||
func toFailureString(err error) string {
|
||||
|
||||
// ClassifyGenericError is the generic classifier mapping an error
|
||||
// occurred during an operation to an OONI failure string.
|
||||
func ClassifyGenericError(err error) string {
|
||||
// The list returned here matches the values used by MK unless
|
||||
// explicitly noted otherwise with a comment.
|
||||
|
||||
|
|
@ -111,7 +114,7 @@ func toFailureString(err error) string {
|
|||
return errwrapper.Error() // we've already wrapped it
|
||||
}
|
||||
|
||||
if failure := toSyscallErr(err); failure != "" {
|
||||
if failure := classifySyscallError(err); failure != "" {
|
||||
return failure
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue