This is how I did it: 1. `git clone https://github.com/ooni/probe-engine internal/engine` 2. ``` (cd internal/engine && git describe --tags) v0.23.0 ``` 3. `nvim go.mod` (merging `go.mod` with `internal/engine/go.mod` 4. `rm -rf internal/.git internal/engine/go.{mod,sum}` 5. `git add internal/engine` 6. `find . -type f -name \*.go -exec sed -i 's@/ooni/probe-engine@/ooni/probe-cli/v3/internal/engine@g' {} \;` 7. `go build ./...` (passes) 8. `go test -race ./...` (temporary failure on RiseupVPN) 9. `go mod tidy` 10. this commit message Once this piece of work is done, we can build a new version of `ooniprobe` that is using `internal/engine` directly. We need to do more work to ensure all the other functionality in `probe-engine` (e.g. making mobile packages) are still WAI. Part of https://github.com/ooni/probe/issues/1335
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
// Package multierror contains code to manage multiple errors.
|
|
package multierror
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// Union is the logical union of several errors. The Union will
|
|
// appear to be the Root error, except that it will actually
|
|
// be possible to look deeper and see specific sub errors that
|
|
// occurred using errors.As and errors.Is.
|
|
type Union struct {
|
|
Children []error
|
|
Root error
|
|
}
|
|
|
|
// New creates a new Union error instance.
|
|
func New(root error) *Union {
|
|
return &Union{Root: root}
|
|
}
|
|
|
|
// Unwrap returns the Root error of the Union error.
|
|
func (err Union) Unwrap() error {
|
|
return err.Root
|
|
}
|
|
|
|
// Add adds the specified child error to the Union error.
|
|
func (err *Union) Add(child error) {
|
|
err.Children = append(err.Children, child)
|
|
}
|
|
|
|
// AddWithPrefix adds the specified child error to the Union error
|
|
// with the specified prefix before the child error.
|
|
func (err *Union) AddWithPrefix(prefix string, child error) {
|
|
err.Add(fmt.Errorf("%s: %w", prefix, child))
|
|
}
|
|
|
|
// Is returns whether the Union error contains at least one child
|
|
// error that is exactly the specified target error.
|
|
func (err Union) Is(target error) bool {
|
|
if errors.Is(err.Root, target) {
|
|
return true
|
|
}
|
|
for _, c := range err.Children {
|
|
if errors.Is(c, target) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// Error returns a string representation of the Union error.
|
|
func (err Union) Error() string {
|
|
var sb strings.Builder
|
|
sb.WriteString(err.Root.Error())
|
|
sb.WriteString(": [")
|
|
for _, c := range err.Children {
|
|
sb.WriteString(" ")
|
|
sb.WriteString(c.Error())
|
|
sb.WriteString(";")
|
|
}
|
|
sb.WriteString("]")
|
|
return sb.String()
|
|
}
|