feat(errorsx): introduce NewTopLevelGenericErrWrapper (#511)
Part of https://github.com/ooni/probe/issues/1733 and diff has been extracted from https://github.com/ooni/probe-cli/pull/506.
This commit is contained in:
parent
d7b9c8f0a8
commit
201f602a40
|
@ -92,3 +92,9 @@ func NewErrWrapper(c Classifier, op string, err error) *ErrWrapper {
|
|||
WrappedErr: err,
|
||||
}
|
||||
}
|
||||
|
||||
// NewTopLevelGenericErrWrapper wraps an error occurring at top
|
||||
// level using the most generic available classifier.
|
||||
func NewTopLevelGenericErrWrapper(err error) *ErrWrapper {
|
||||
return NewErrWrapper(ClassifyGenericError, TopLevelOperation, err)
|
||||
}
|
||||
|
|
|
@ -102,3 +102,19 @@ func TestNewErrWrapper(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestNewTopLevelGenericErrWrapper(t *testing.T) {
|
||||
out := NewTopLevelGenericErrWrapper(io.EOF)
|
||||
if out.Failure != FailureEOFError {
|
||||
t.Fatal("invalid failure")
|
||||
}
|
||||
if out.Operation != TopLevelOperation {
|
||||
t.Fatal("invalid operation")
|
||||
}
|
||||
if !errors.Is(out, io.EOF) {
|
||||
t.Fatal("invalid underlying error using errors.Is")
|
||||
}
|
||||
if !errors.Is(out.WrappedErr, io.EOF) {
|
||||
t.Fatal("invalid WrappedErr")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user